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
while wait(1) do if not workspace:FindFirstChild("box") then print("reshuffling"); local msg = Instance.new("Message", workspace) msg.Text = "No more boxes! Reshuffling..." local clone = game.ServerStorage.box:Clone() clone.Parent = workspace wait(3) msg:Destroy() end end
script in the box
game.Players.PlayerAdded:Connect(function(plr) local leader = plr:WaitForChild("leaderstats") local box = leader:FindFirstChild("Boxes Destroyed") script.Parent.Touched:Connect(function(hit) local h = hit.Parent:WaitForChild("Humanoid") if h ~= nil then wait() box.Value = box.Value + 1 script.Parent:Destroy() end end) end)
Any help would be greatly appreciated oWo
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.
script.Parent.Touched:Connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum then local plr = game.Players:GetPlayerFromCharacter(hum.Parent) if plr then local box = plr.leaderstats["Boxes Destroyed"] box.Value = box.Value + 1 script.Parent:Destroy() end end end)
I haven't put these scripts to test as I am quite tired so apologies if you experience any errors!