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

i got this error attempt to index nil with 'FindFirstChild' what should i do?

i try this script to track the leaderstats folder but i dont find the way. Please help me

local waw = game.ServerStorage:WaitForChild("Give")
local hum = script.Parent:WaitForChild("Humanoid")

hum.Died:Connect(function(player)
	local Leaderstats = player:FindFirstChild("leaderstats")
		local kepintaran = Leaderstats.Kepintaran.Value
		waw:Fire(20*(kepintaran+1))
	end)

2 comments

0

Is it a local script

0

i think it is not

1 answer

hum.Died don't returns a player instance, the error is because player is nil. As character is script.Parent, you can use game.Players:GetPlayerFromCharacter(script.Parent) to get player:

local waw = game.ServerStorage:WaitForChild("Give")
local player = game.Players:GetPlayerFromCharacter(script.Parent)
local hum = script.Parent:WaitForChild("Humanoid")

hum.Died:Connect(function()
    local Leaderstats = player:FindFirstChild("leaderstats")
        local kepintaran = Leaderstats.Kepintaran.Value
        waw:Fire(20*(kepintaran+1))
    end)

Edit: As you're doing it in a dummy, you need to get player via its name:

local waw = game.ServerStorage:WaitForChild("Give")
local player = game.Players:FindFirstChild(script.Parent.Name) -- this may change based on wher you have player name on the dummy
local hum = script.Parent:WaitForChild("Humanoid")

hum.Died:Connect(function()
    local Leaderstats = player:FindFirstChild("leaderstats")
        local kepintaran = Leaderstats.Kepintaran.Value
        waw:Fire(20*(kepintaran+1))
    end)

3 comments

0

but i do this script inside a dummy. not a player

0

Then set the player to game:GetService("Players").LocalPlayer

0

I edited it

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