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

Why wont this respawn the object? Code Printed below

Asked by
NotPix 2
7 years ago
local PP = game:GetService("PointsService")
local Money = {}
local Luck = game.Workspace.Settings.PPRate

local function getParts(obj)
    for i,v in pairs(obj:GetChildren())do
        if obj:IsA("Part")then
            table.insert(Money,obj)
        end
        getParts(v)
    end
end
getParts(script.Parent)


function Touch(plr,loot)
    if not plr:FindFirstChild("leaderstats")then return end
    local type = loot.Name
    local add = loot.Amount.Value
    plr.leaderstats[type].Value = plr.leaderstats[type].Value+add
    local oldParent = loot.Parent
    loot.Parent = nil
    delay(5,function( )loot.Parent = oldParent end) 
    if PP then
        if PP:GetAwardablePoints()>0 and math.random(1,100)< Luck.Value then
            PP:AwardPoints(plr.userId,add)
        end
    end

end

function addPart(part)
    local backup = part:Clone()
    local parent = part.Parent
    part.Touched:connect(function(hit)
        if game.Players:GetPlayerFromCharacter(hit.Parent)then
            Touch(game.Players:GetPlayerFromCharacter(hit.Parent),part)
        end
    end)
end


for i=1,#Money do
    if Money[i]:IsA("Part")then     
        addPart(Money[i])
    end
end
0
Give explaination. We can't just do stuff with random code. (Explaination is not one scentance, its a whole paragraph.) RubenKan 3615 — 7y
0
delay(5,function( )loot.Parent = oldParent end) doesnt work if that helps u NotPix 2 — 7y

Answer this question