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

after i click "coin" it destroys itself and clones but the clone is just a part without any script?

Asked by 3 years ago
Edited by imKirda 3 years ago

my code is

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    local PlayerPoints = player.leaderstats.Points
    local coin = game.Workspace.Coin
    PlayerPoints.Value = PlayerPoints.Value + 1
    coin:Destroy()
    wait(3)
    local coin = coin:Clone()
    coin.Parent = game.Workspace
end)

i alr have leader stats

1 answer

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago

it is because clone is already removed, you can put a replacement on ReplicatedStorage and do

local Coin = game:GetService("ReplicatedStorage").Coin

game:GetService("Players").PlayerAdded:Connect(function(player)
    local debounce = false
    local CoinClone = Coin:Clone()
    CoinClone.Parent = game.Workspace

    local function SpawnCoin()
        player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1
        game.Workspace.Coin:Destroy()
        wait(3)
        local CoinClone1 = Coin:Clone()
        CoinClone1.Parent = game.Workspace
    end

    script.Parent.ClickDetector.MouseClick:Connect(SpawnCoin)
end

I hope this works? I think there is some better solution, you could check out https://devforum.roblox.com/t/creating-a-coin-collection-system/559120 because my poor scripting

Ad

Answer this question