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

LocalScript (PlayerGui) enabling script (workspace) isn't working?

To keep it short, here's how the function works. You click on a part, part clones 2 localscripts into PlayerGui. One localscript changes the camera, then deletes itself. Second localscript is a input keydown function; when pressed Q, functions. After the part is done cloning, it puts itself into lighting to get out of the way. When you press Q it brings the part back into workspace to be clicked again. HOWEVER, everything within the keypress script works but when the part goes into workspace, it doesn't work anymore. It is enabled, there are no "if" statements preventing it.

Here is the line of code for the clicking part:

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)

--top part is for selectionboxes

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
		Ready = true
		script.Parent.Parent = game.Lighting
	end
end)

Now here is the line of code for the keypress:

local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer


game:GetService("UserInputService").InputBegan:Connect(function(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.Q then
		camera.CameraSubject = player.Character.Humanoid
	
		if player.PlayerGui:FindFirstChild("SelectionBox") then
			player.PlayerGui.SelectionBox:Destroy()
		end
		local sup = game.Lighting.KitchenPuzzleBruh
		sup.Parent = game.Workspace
		sup.Ready.Value = true
		script:Destroy()
	end
end)

This is super frustrating considering there are no error messages, I've tried adding remote events, yet nothing works... Any responses would be super appreciated.

EDIT: This is the script that makes sure you got the puzzle correct


local one = game.Workspace.KitchenTrap:FindFirstChild("One")
local two = game.Workspace.KitchenTrap:FindFirstChild("Two")
local three = game.Workspace.KitchenTrap:FindFirstChild("Three")
while true do
	wait(0.1)
	if one.SurfaceGui.TextBox.Text == "3" and two.SurfaceGui.TextBox.Text == "8" and  three.SurfaceGui.TextBox.Text == "0" then
		one.SurfaceGui.TextBox.TextColor3 = Color3.new(255, 255, 255)
		two.SurfaceGui.TextBox.TextColor3 = Color3.new(255, 255, 255)
		three.SurfaceGui.TextBox.TextColor3 = Color3.new(255, 255, 255)
		repeat wait()
			game.Workspace.KitchenTrap.Lock.Transparency = game.Workspace.KitchenTrap.Lock.Transparency + 0.1
		until game.Workspace.KitchenTrap.Lock.Transparency >=1 
		local sup = game:GetService("ReplicatedStorage").GettingPlayer
		sup:Clone()
		sup.Parent = game.Workspace
		game.Workspace.KitchenTrap.Lock:Destroy()
		script.Parent:Destroy()
	end
end

5 comments

0

I should also mention that the selection box part doesn't work either (the whole script doesn't work)

0

Also another interesting thing to add, I tried just making another script that printed something and enabling it from the keypress to see if it was just the clicking script itself. However, nothing printed when activated by this keypress script

0

add that script to this thread. i want to see if you're doing something wrong there, or maybe its not placed appropriately

0

^ bc I have a while true script running to see if you got the puzzle correct as well

0

For the while true script, The "GettingPlayer" part is a touch event that just changes the camera back

1 answer

Figured it out. Added the mouseclick event into the keypress localscript.

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