The problem with your script is that
A) You're assuming that ANYTHING that touches that part, is part of a Player. It could just be a random part that falls on it. :P
and B) The line local player = hit.Parent
What's wrong with that is that, say I go and touch the part, Okay? It'll just say that my Leg/Arm's Parent is a Player, when it's ACTUALLY my character. (Unless you keep your leaderstats in people's character, then all of this is wrong. :c )
So, first you need to make sure it's a Player, and then get the Player. You can do both of these, by just using the :GetPlayerFromCharacter() method, in Players, like so.
Players = game:GetService("Players")
function onTouched(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if Player ~= nil then
end
end
script.Parent.Touched:connect(onTouched)
You see, the :GetPlayerFromCharacter() method does, basically, what it's name implies it does. With this, it will get the Player's Player, and not the Character.
Now that you have the Player, all that's left is to award the points, and, assuming it'd called Logs like in your script example, I'll just try add it like this...
Players = game:GetService("Players")
function onTouched(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if Player ~= nil then
if player and player.leaderstats and player.leaderstats.Logs then
player.leaderstats.Logs.Value = player.leaderstats.Logs.Value + 5
end
end
end
script.Parent.Touched:connect(onTouched)
Well, it should work. Looks about right...
Hope this helped. :)
If it didn't please don't hate me. :(
2 comments
Check mine. It should work.
How is this -1 point?