#Need help, my function can't find my leaderstats when the player touches the model

1 messages · Page 1 of 1 (latest)

high kayak
#

Need help for this script


local img = game.StarterGui.AddCoinsGui:FindFirstChild("ImageLabel")
local text = game.StarterGui.AddCoinsGui:FindFirstChild("TextLabel")
local trusses = game.Workspace.Spawn.Trusses:FindFirstChild("Trusses")
local Players = game:GetService("Players")

for _, v in pairs(trusses:GetChildren()) do
    if v:IsA("TrussPart") then
        v.Touched:Connect(function(player)
        if player:FindFirstChild("leaderstats") then
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 5
            print("+5")
        end

        end)
    end
    
    
    
end

It is supposed to give the player + 5 coins when he touches the trussparts in the model but it isn't finding the leaderstats

coarse hearth
#

v.Touched:Connect(function(player) isn't the actual player, but rather its the part that touched the truss.

Use Players:GetPlayerFromCharacter() to get the actual instance of the Player and then use hit:FindFirstAncestorOfClass("Model") to see if the touched part is the character model.