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

Why Wont The Coin When i touch it change the leader board to 1 coin ?

Asked by 4 years ago
Edited 4 years ago
local db = true
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        if db == true then
            db = false
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
            script.Parent.Parent.Parent.Model:Destroy()
        end
    end
end)

error: 12:20:25.556 - Touched is not a valid member of Model

0
make sure script.Parent is a part raid6n 2196 — 4y

1 answer

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Change script.Parent to script.Parent.Part and use waitforchild just in case the leaderstats hasnt loaded yet

local db = true
script.Parent.Part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        if db == true then
            db = false
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            player:WaitForChild("leaderstats"):WaitForChild("Coins").Value = player.leaderstats.Coins.Value + 1
            script.Parent.Parent.Parent.Model:Destroy()
        end
    end
end)
Ad

Answer this question