Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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

Log in to vote
2
Answered by
Tigerism 220 Moderation Voter
8 years ago

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)


0
thank you madkaratemans 0 — 8y
Ad

Answer this question