Ad
Log in to vote
0

How would I find the local player in a server script?

Asked by 7 days ago
Edited 7 days ago

I am making a script, that every time the npc dies, the player gets +10 coins to their leader stats named "coins". I use the player added function but it only adds plus 10 once. then when the npc health value reaches 0 again, it doesn't add +10. Please help!

local health = script.Parent --script is in a health value of my npc

health.Changed:Connect(function() if health.Value <= 0 then local currentposition = script.Parent.Parent.HumanoidRootPart.CFrame health.Value = 10 script.Parent.Parent.HumanoidRootPart.CFrame = turtlerespawn.CFrame

    --Utter confusion--

    game.Players.PlayerAdded:Connect(function(plr)
        local player = plr
        print(player.Name)
        print("Plus 10")
        player.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 10
    end)
    wait(5)
    script.Parent.Parent.HumanoidRootPart.CFrame = currentposition
end

    ----------------------------------------------------------------------------------------

end)

0
the coded part is the part that i'm trying to find the local player in. Carlowskey 11 — 7d

1 answer

Log in to vote
0
Answered by 7 days ago

if you are killing the npc, make something that will tag the player that hits the npc like in the default sword. If you want assists or damage requirements, make a number that shows the dmg done instead of just tagging the player.

Ad

Answer this question