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

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

Asked by
Prioxis 673 Moderation Voter
10 years ago

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?

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). jav2612 180 — 10y

2 answers

Log in to vote
1
Answered by
Hybric 271 Moderation Voter
10 years ago
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)
0
Thank you! Prioxis 673 — 10y
Ad
Log in to vote
-3
Answered by 10 years ago

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

Answer this question