✓ Accepted answer
Hello, ThatOneKid7590.
Your script currently gives everyone in the game 20 points since you have used a for loop that iterates through all the players in the Players folder. You want to give points to the localplayer, not all players. In your case, the for loop is completely useless..
Lets restart from the beginning
local brick = script.Parent
function onTouched(hit)
end
brick.Touched:connect(onTouched)
It is to be noted that the Hit argument I've used represents the part that touched it. In our case, it could be your characters right leg.
Now, we will make sure that whatever touched it is indeed a player, and not a brick.
if(hit.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent)) then
end
After that, we want to award the player 20 points. The player being hit.Parent.
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
leaderstats.Points.Value = leaderstats.Points.Value +20
end
brick:Destroy()
The final code should look like this:
EDIT: I forgot to add an end in my final code. Sorry for the inconvenience. Should work now
local brick = script.Parent
function onTouched(hit)
if(hit.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent)) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
leaderstats.Points.Value = leaderstats.Points.Value +20
end
brick:Destroy()
end
end
brick.Touched:connect(onTouched)
Cheers!
1 comment
I forgot an end in my script. Should work fine now. Cheers!