script.Parent.Touched:Connect(function(Hit))
if Hit.Parent:FindFirstChild("Humanoid") and game.Players:FindFirstChild("Hit.Parent.Name") then
local Player = game.Players:FindFirstChild("Hit.Parent.Name")
local leader = Player:FindFirstChild("leaderstats")
if leader ~= nil then
local Bucks = leader:FindFirstChild("Bucks")
if Bucks ~= nil then
Bucks.Value = Bucks.Value + 100
end
end
end
end)
.Touched events give the part that hit as the parameter, not the player. If you look at @Crygen54’s response, you can see an example of how to get the player there.
Touched passes the part that touched this part. You need to first check and see if it belongs to a character, if it does then you check if that character belongs to a player.
if hit.Parent:FindFirstChild('Humanoid') then -- check if char
local player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
if player then
-- touched by a players character
player.leaderstats.Bucks.Value = player.leaderstats.Bucks.Value + 100
end
end