Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

ClickDetector Part Not Functioning After First Use?

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

0

If I remember correctly, MouseClick should be run on the server. I think it actually does work on the client, but it has some side-effect (maybe similar to running PlayerAdded on the client). It might not be your problem, but something to think about

0

And that would apply to all ClickDetector events, too

0

I'd also like to point out that script.Parent.Parent is 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?

0

It works once, meaning the function itself works. All i'm doing is trying to do it again but it isn't working

0

Yes it functions correctly, it goes to lighting and back into workspace

0

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.

0

Line 9 of your second script. Shouldn't that object be cloned into workspace?

0

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)

0

That got rid of the error, and the script but didn't fix the problem

1 answer

So I figured out why it isn't working. Basically for whatever reason the localscript is executing its correct function. Whatever script in workspace that is called by this localscript, does not work.

1 comment

0

For example, the localscript that enables a script in workspace to print "sup", it says the script is enabled but does not function

This discussion is preserved as it was. New answers, comments, and votes are closed.