I'll make this short. I have a puzzle area where you click on the part (what I'm talking about), it moves to Lighting, Changes the CameraSubject from a localscript cloning, and clones a keypress script into PlayerGui. CODE:
script.Parent.ClickDetector.MouseHoverEnter:Connect(function(Clicker)
if script.Parent:FindFirstChild("SelectionBox") then
print("googoo")
else
local selection = Instance.new("SelectionBox")
selection.Color3 = Color3.new(153, 153, 153)
selection.LineThickness = 0.03
selection.Parent = Clicker.PlayerGui
selection.Adornee = script.Parent
end
end)
script.Parent.ClickDetector.MouseHoverLeave:Connect(function(Clicker)
if Clicker.PlayerGui:FindFirstChild("SelectionBox") then
Clicker.PlayerGui.SelectionBox:Destroy()
end
end)
--SelectionBox Code Above (might be irrelevant)
local Ready = true
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
if Ready == true then
Ready = false
local keypress = script.Parent.KeyPressing:Clone()
keypress.Parent = plr.PlayerGui
keypress.Disabled = false
local cloneme = script.Parent.LocalScript:Clone()
cloneme.Parent = plr.PlayerGui
cloneme.Disabled = false
local pieces = game:GetService("ReplicatedStorage").PuzzleKitchenStuff:Clone()
pieces.Parent = game.Workspace
pieces.Script.Disabled = false
if plr.PlayerGui:FindFirstChild("SelectionBox") then
plr.PlayerGui.SelectionBox:Destroy()
end
script.Parent.Parent = game.Lighting
Ready = true
end
end)
So everything works fine until I press the key. Everything within the key functions as told, but the part just doesn't work when it goes back into Workspace..
CODE FOR KEYPRESS:
local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
game:GetService("UserInputService").InputBegan:Connect(function(inputObject,gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.Q then
camera.CameraSubject = player.Character.Humanoid
game.Lighting.KitchenPuzzleBruh.Parent = game.Workspace
if player.PlayerGui:FindFirstChild("SelectionBox") then
player.PlayerGui.SelectionBox:Destroy()
end
script:Destroy()
end
end)

10 comments
If I remember correctly,
MouseClickshould be run on the server. I think it actually does work on the client, but it has some side-effect (maybe similar to runningPlayerAddedon the client). It might not be your problem, but something to think aboutAnd that would apply to all
ClickDetectorevents, tooI'd also like to point out that
script.Parent.Parentis extremely confusing, if you're actually trying to set the parent of the parent. Do you know that it's doing what you want it to?It works once, meaning the function itself works. All i'm doing is trying to do it again but it isn't working
Yes it functions correctly, it goes to lighting and back into workspace
Something to mention as well, the local script in PlayerGui is suppose to destroy itself but never does. OUTPUT CODE: Something unexpectedly tried to set the parent of LocalScript to NULL while trying to set the parent of LocalScript. Current parent is PlayerGui.
Line 9 of your second script. Shouldn't that object be cloned into workspace?
Clonetrooper said add it to debris for 0 seconds https://devforum.roblox.com/t/remove-the-something-unexpectedly-tried-to-set-the-parent-of-x-to-null-while-trying-to-set-the-parent-of-x/27414
No, because I'm not trying to clone it, rather just trying to put it back into workspace (I've tried cloning, disabling and re-enabling the script, nothing works)
That got rid of the error, and the script but didn't fix the problem