Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

attempt to index global 'f' (a nil value) how to fix?

im trying to make a block teleport me, but it outputs the title of the question

this is the code:



function touched(touch)

while (h == 1) do
	
f = script.Parent:FindFirstChild("Humanoid")


	
f.Position = Vector3.new(0,55,0)



wait(0.1)	
	
end	
	
	
end

h = 1
game.Players.PlayerAdded:connect(touched)

1 answer

Your problem is game.Players.PlayerAdded:connect(touched) If it's a brick you touch for it to teleport you, put that script inside of a brick and replace that line with:

script.Parent.Touched:connect(touched)

Then in the code, you need to make sure f is a true value. Add if not f then return endto make sure the rest of the code will not run.

Final code:

function touched(touch)

while (h == 1) do

f = script.Parent:FindFirstChild("Humanoid")
if not f then return end


f.Position = Vector3.new(0,55,0)



wait(0.1)   

end 


end

h = 1
script.Parent.Touched:connect(touched)


1 comment

0

thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.