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

I need help with a script that will reward the player with points (not player points) ?

here is my script its for whenever someone touches a brick it'll reward the player with 5000 points but theres a error with the code heres the script

local Player = hit.Name -- Error in script...
function onTouched(hit)
game.Players.Player.leaderstats.Points.Value = game.Players.Player.leaderstats.Points.Value + 50000
end
script.Parent.Touched:connect(onTouched)

why is local Player = hit.Name an error?

1 comment

0

It's an error because you can only use "hit" inside the function. You're trying to find something that might not yet exist because the event hasn't been activated yet (Something hasn't touched the part yet).

2 answers

✓ Accepted answer
function onTouched(hit)
local Player = hit.Parent:findFirstChild("Humanoid")
if (Player ~= nil) then
game.Players:findFirstChild(Player.Parent.Name).leaderstats.Points.Value = 
game.Players:findFirstChild(Player.Parent.Name).leaderstats.Points.Value + 50000
end

script.Parent.Touched:connect(onTouched)

1 comment

0

Thank you!

I don't think you put "Name" I think you put something else, like your name. But tweak the first part a bit.

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