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

Script works only when Parent is workspace from the start?

Asked by
MexheCo 46
5 years ago

Let me explain that better. Basically, I have a part, and when the player touches it, it will fire a remote event that runs some client-side code.

The server script (below) works fine when the object is a child of the workspace from the start. However, if I try to change the parent of the crate via scripting (i.e move the crate from ReplicatedStorage to Workspace) the script suddenly does nothing. Can anyone help?

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local plr = workspace[hit.Parent.Name]
        local player = game.Players:GetPlayerFromCharacter(plr)

        game.ReplicatedStorage.CoinChestEvent:FireClient(player)

        script.Parent.Parent:Destroy()


        end
    end)

0
Server scripts only run when descendants of workspace, serverscriptservice and backpack. So you'll need another script to do this. -@/9 why are you indexing the player from the workspace? User#24403 69 — 5y
0
Change it to 'local plr = hit.Parent.Name' on line 3 instead of adding that workspace. TheOnlySmarts 233 — 5y

Answer this question