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

Why does the second time my script runs, it gives out a parent locked error?

Asked by 5 years ago
Edited 5 years ago

This question has been solved by the original poster.

I've tried researching this and have added a few :WaitForChild() and rearranged the script quite a bit.

The error is in the server tab, and reads:

The Parent property of ScreenGui035 is locked, current parent: NULL, new parent PlayerGui
Stack Begin
Script 'Workspace.SCP-035.touchedscp', line 22
Stack End

I have found 2 lines of code that are causing an error in the script:

knife.Parent = player:WaitForChild("Backpack")
effectclone.Parent = player.PlayerGui

My full code is:

debounce = false

knife = game.ServerStorage.MadMurdererKnife:Clone()
newshirt = game.ServerStorage.Shirt:Clone()
newpant = game.ServerStorage.Pants:Clone()
effect = game.ServerStorage:WaitForChild("ScreenGui035")
effectclone = effect:Clone()
script.Parent.Touched:connect(function(touched)
    local player = game.Players:GetPlayerFromCharacter(touched.Parent)
 if touched.Parent:FindFirstChild("Humanoid") and debounce == false and  player:FindFirstChild("PlayerGui") then

    debounce = true
----------------------------------------------------------
local humanoid = touched.Parent:WaitForChild("Humanoid")
local scp035 = game.ServerStorage["SCP-035"]:Clone()
local head = touched.Parent:FindFirstChild("Head")
----------------------------------------------------------
head.BrickColor = BrickColor.new("Really black")
humanoid:RemoveAccessories()
    wait()
touched.Parent.Humanoid:AddAccessory(scp035)
effectclone.Parent = player.PlayerGui
knife.Parent = player.Backpack
touched.Parent.Shirt:Destroy()
touched.Parent.Pants:Destroy()
    wait()
newshirt.Parent = touched.Parent
newpant.Parent = touched.Parent
    wait(2)
humanoid.Died:connect(function()
    debounce = false
end)
    end
end)
0
Answered by self since no one else had. I just had to send the items back to ServerStorage because they were getting sent into the void after the Player had died. Grim_Reaper29 0 — 5y

Answer this question