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

There say index local player something I dont get it, Help me?!

So this is the error that It displays: "12:46:54.259 - Workspace.Grill.Trigger.Script:8: attempt to index local 'player' (a nil value)"

Here is the script:

local Trigger = workspace:WaitForChild("Grill"):WaitForChild("Trigger")

Trigger.Touched:connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)	
	
	if hit.Parent.Name == "Raw Meat" then
		for i = 5,0,-1 do
			print(player.Name)
			player.Character.Humanoid.WalkSpeed = 0
			wait(1)
		end
	end
end)

3 comments

0

Strange. Player is already defined as a variable.

0

I know

0

@Void_Frost Not working.

1 answer

Try this:

local Trigger = workspace:WaitForChild("Grill"):WaitForChild("Trigger")

Trigger.Touched:connect(function(hit)
if  game.Players:GetPlayerFromCharacter(hit.Parent)  then
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)  

    if hit.Parent.Name == "Raw Meat" then
        for i = 5,0,-1 do
            print(player.Name)
            player.Character.Humanoid.WalkSpeed = 0
            wait(1)
end
        end
    end
end)

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