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

when i clone a script from the replicatedstorage to the workspace the script doesnt work??

Asked by 6 years ago
Edited 6 years ago

so heres my issue: i am making a box destroying minigame and u have to destroy boxes to get more points. when there is no more boxes in the workspace, its supposed to clone one box from the replicated storage to the workspace, and it does that. and the script from the box in the workspace works. however when the one in the replicated storage is cloned into workspace, that scrip(which is the same) no longer works? help!!

script in serverscriptservice

01while wait(1) do
02if not workspace:FindFirstChild("box"then
03 
04     print("reshuffling");
05     local msg = Instance.new("Message", workspace)
06    msg.Text = "No more boxes! Reshuffling..."
07    local clone = game.ServerStorage.box:Clone()
08    clone.Parent = workspace
09    wait(3)
10    msg:Destroy()
11end
12end

script in the box

01game.Players.PlayerAdded:Connect(function(plr)
02local leader = plr:WaitForChild("leaderstats")
03local box = leader:FindFirstChild("Boxes Destroyed")
04script.Parent.Touched:Connect(function(hit)
05    local h = hit.Parent:WaitForChild("Humanoid")
06    if h ~= nil then
07        wait()
08    box.Value = box.Value + 1
09    script.Parent:Destroy()
10    end
11end)
12end)

Any help would be greatly appreciated oWo

1 answer

Log in to vote
1
Answered by
xEmmalyx 285 Moderation Voter
6 years ago
Edited 6 years ago

I'm not sure as I haven't done any tests but it could be that the script in the box runs after moving it to the workspace. Meaning the PlayerAdded never runs for old/current players. Placing this script in the box may do you better.

01script.Parent.Touched:Connect(function(hit)
02    local hum = hit.Parent:FindFirstChild("Humanoid")
03    if hum then
04        local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
05        if plr then
06            local box = plr.leaderstats["Boxes Destroyed"]
07            box.Value = box.Value + 1
08            script.Parent:Destroy()
09        end
10    end
11end)

I haven't put these scripts to test as I am quite tired so apologies if you experience any errors!

0
tysm it works :) nzsalty16 81 — 6y
0
np, hope you have a great week! xEmmalyx 285 — 6y
Ad

Answer this question