Most confusing Error from localscript

wanted to make localscript that usually when player touchs but this error keep bothering me

so basically. when i was making localscript whatever player touch it and localscript do something. well this happen

local gas = workspace.giole:FindFirstChild("gas")
if gas then
gas.Touched:Connect(function()
	print("localscript hated you :DDDDDD")
end)
end

it didnt print at all :confused:

2 Likes

what is the error that you recieve?

Also you said the player touches the gas. However in the script it says that anything can touch the gas, so I would script it so only the player can touch the gas then it prints out the print statement.

Please make sure that the object exists in the workspace by using FindFirstChild() and ensure that the name of the object is valid. I hope this would assist you resolve the problem.

Maybe try adding a warning to let you know if gas was found:

local gas = workspace.giole:FindFirstChild(“gas”)

if gas then
	gas.Touched:Connect(function()
		print("localscript hated you :DDDDDD”)
	end)
else
	warn(“Did not find gas.”)
end

There is already here, Toxich. I check anything

printed as warning. :frowning: i tried anything

There is no error yet. i put if gas then end
i think localscript need glass to see again

local giole = workspace:WatiForChild(“giole”)
local gas = giole:WatiForChild(“gas”)

where’s the local script located

Why would you need the if gas then ? You can do :WaitForChild()

1 Like

what is difference waitforchild between FindFirstChild()

WaitForChild() waits for the child to be created or loaded. If it doesn’t exist, then the script waits until the child exist.

FindFirstChild() will attempt to find a child, if it doesn’t find the child, it will return nil.

1 Like

Thank you, i thought waitforchild and findfirstchild are same thing

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.