I am remaking a game of mine, but whenever I try to tween the part i´m working on, it returns the error
Workspace.core.Script:4: attempt to call a table value
although TweenService requires a table to work.
Here´s my code:
temp = workspace.values.core.temp
tw = game:GetService("TweenService")
while true do
g = tw:Create(script.Parent,TweenInfo(10-(temp.Value/200),Enum.EasingStyle.Circular,Enum.EasingDirection.InOut),{Size = Vector3.new(5,5,5)})
g:Play()
g.Completed:Wait()
end
I tried changes like putting script.Parent.Size as the Instance and then just the Vector3 in the goal, but none of it worked, all of the things I tried returned the error above.
Edit: Nevermind, I forgot to add the .new after TweenInfo
To use constructors in roblox, you have to do Class.new(). So for TweenInfo it has to be TweenInfo.new()
Related
local Player = game.Players.LocalPlayer
local PlayerCash = Player:WaitForChild("leaderstats"):WaitForChild("Strength")
local Mouse = Player:GetMouse()
local amount = 50
script.Parent.Activate:Connect(function()
game.Players.LocalPlayer.leaderstats.money.Value = game.Players.LocalPlayer.leaderstats.money.Value + amount
end)
I am trying to make a code to give Strength when you click. When I press 'Play' it doesn't work. All it says in the output is
'attempt to index function with 'Connect'.'
The error "attempt to index [type] with [field name]" means that you are incorrectly using something like an object, and you are trying to access some field on it.
In your case, this error is pointing at the line : script.Parent.Activate:Connect.This says that script.Parent.Activate is a function and not a table, and you cannot call Connect on a function. This is just to help us figure out what is wrong with our code.
Since you working with Tools, there is a simple fix. Instead of using the Activate function, you are looking for the Activated event. So just change update that line like this :
script.Parent.Activated:Connect(function()
It connects a function to an event that happened, like this:
local tool = script.Parent
-- It connects the event (the tool being equipped) to a function.
tool.Equipped:Connect(function()
-- CODE
end)
Also, the answer above is how you can fix your problem and here's a shortcut: You have defined "Player" and you could've used it inside the function. Have a great day and God bless everyone here.
local garbage = game.Teams["Glizzy Garbage"]
local player = game.Players.LocalPlayer
if player.leaderstats.Pounds.Value <= 1000 then --this is the line that the output is detecting the error
player.Team = garbage
end
I am trying to make it where when the player reaches a certain amount of 'pounds' then they will automatically receive a roll. I've searched through many youtube videos and haven't found a fix or an alternative way to do this, and I'm not sure why this isn't working. This script is located in the workspace. All help is appreciated.
The LocalPlayer object is only exposed in LocalScripts. Because you're using a Script in the Workspace, you'll have to access the player object another way. It's also a good idea to handle this kind of logic inside a function that is fired any time the Pounds value changes.
Try using the game.Players.PlayerAdded signal :
local garbage = game.Teams["Glizzy Garbage"]
game.Players.PlayerAdded:Connect(function(player)
local Pounds = player.leaderstats.Pounds
Pounds.Changed:Connect(function(value)
if value <= 1000 then
player.Team = garbage
end
end)
end)
Mine is just
local plrStage = plr.leaderstats.Stage.Value
try instead of putting team name put team colour
also use
player.Team.Service = garbage
end)
I'm trying to make a game but it heavily relies on the mouse but an error occurs saying 'attempt to index nil with 'GetMouse'' and no matter what I do it creates this error. Maybe my game is not updated (I think it is updated). I asked a similar question before but now I'm sure it is Roblox Studio's fault.
Heres the code:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Block = game.ServerStorage.Experimental
function place()
PlacedBlock = Block:Clone()
PlacedBlock.Parent = workspace
PlacedBlock.Position = Mouse.Hit.p
end
Mouse.MouseButton1Click:Connect(place)
The first problem is that MouseButton1Click isn't a valid member of GetMouse(). MouseButton1Click is used for stuff such as GUI objects. Button1Down is used for GetMouse(). Also, .p is deprecated, use .Position instead.
Secondly, you need to place your part in ReplicatedStorage, not ServerStorage. The client can not access ServerStorage. Make sure that you are using a LocalScript.
Fixed:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Block = game.ReplicatedStorage.Experimental
function place()
PlacedBlock = Block:Clone()
PlacedBlock.Parent = workspace
PlacedBlock.Position = mouse.Hit.Position
end
mouse.Button1Down:Connect(place)
Now there's one problem with this. When you place the part, it will only show for you and it wont show for anyone else. To fix this, you will need to use Remote Events.
I am making a Roblox game, and I need to detect a player's team somehow.
My code currently looks like this:
script.Parent.Touched:Connect(function(part)
local plr = part.Parent.Name
if (game.Players:FindFirstChild(plr).Team == "Police") then
....
end
end)
And when I touch that part (it's an invisible wall), it gives me an error: Workspace.Part.Script:3: attempt to index a nil value
What am I doing wrong?
Edit: I found out it can't find my name in game.Players, because now I tried:
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:FindFirstChild(hit.Parent.Name)
if (plr.Team == "Police") then
...
And now I get Workspace.Part.Script:3: attempt to index local 'plr' (a nil value)
Edit2: Now I tried printing plr (game.Player:FindFirstChild(hit.Parent.Name)) and it was ' Miniller', not 'Miniller', and now I didn't get any errors, but the code below also did nothing..
I solved it by not using variables AND not "Police", it's game.Teams.Police, so code:
if (game.Players:FindFirstChild(hit.Parent.Name).Team = game.Teams.Police
...
ok, I've been starring at this error message for better part of a day now.
I'm trying to make a simple eventlistner to run when someone touches a button. The problem is that hower ever I decided to name it it says it's nil and cannot be used.
I'm working on a scene with the name "scene", self.view named "sceneGroup". The rectangle I try to add a listner to is called "mMnew" and is in the group called "mMnewU".
I've tried to change the name between all of those. At first I hade problem with adding the eventlistener but solved it, problem was not the same sulution worked for the listners name.
Listner:
function scene.mMnewUeser:touch(event)
if(event.phase == "begun")then
local test1 = display.newRect(100,150,40,40)
test1:setFillColor(0,1,0)
print("Touch found")
end
end
Added listner:
scene:addEventListener("touch", scene.mMnewUeser)
I'm still pretty green with this language and used to code in JavaC, php, html, sql and AS3.0. Sorry for my rockie problems!
UPDATE:
After adding a few simple checkpoints check in the code, it would seam that it refuses to run the function scene:create(event) my scene does hwoerver get created by local composer = require("composer")
local scene = composer.newScene()
This
function scene.mMnewUeser:touch(event)
is not the correct syntax. You probably meant to have:
function scene:mMnewUeser(event)
which means you're adding new method with a name mMnewUeser to scene object. Then you can just use it as touch listener the way you did in the last line of code. See an explanation of the difference between . and : here.