Need help with a local script

  1. What do you want to achieve?
    trying to disable a local script with another local script

  2. What is the issue? Include screenshots / videos if possible!
    script just doesnt work

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i tried using boolvalue, changing local script (the one trying to disable) to a script and using a remote event and using script.disable = true none worked


local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Bool = script.Value.Value


Mouse.Button1Down:Connect(function()
	if workspace:FindFirstChild("Location") then
		workspace.Location:Destroy()
	end
	local Part = Instance.new("Part")
	Part.Shape = "Cylinder"
	Part.Size = Vector3.new(0.25, 2, 2)
	Part.Anchored = true
	Part.CanCollide = false
	Part.Orientation = Vector3.new(0,0,-90)
	Part.Parent = workspace
	Part.Position = Mouse.Hit.p
	Part.Name = "Location"
	Part.Material = "Plastic"
	Part.BrickColor = BrickColor.new("Lime green")
	
	local Character = Player.Character
	Character.Humanoid:MoveTo(Mouse.Hit.p)
	
	Part.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			Part:Destroy()
		end
	end)
end)

the script i am trying to disable

local button = script.Parent
local Bool = script.Parent.Bool.Value
local ClickToMoveBool = game.StarterGui.ClickMove.Value


button.MouseButton1Click:Connect(function()
	if Bool == true then
		button.TextColor3 = Color3.new(1, 0, 0)
		Bool = false
		ClickToMoveBool.Value = false
	elseif Bool == false then
		button.TextColor3 = Color3.new(0, 1, 0)
		Bool = true
		ClickToMoveBool.Value = true
	end
end)

the script i am using to disable

oddly enough when checking the explorer the script is disabled but it still works somehow

2 Likes

Instead of disabling the script,

you could just have a check in the script you want to disable and if the bool is false then dont execute

also:
local Bool = script.Parent.Bool.Value

will not work because that just returns the value at the moment so when yoiu want to change it u should do
local Bool = script.Parent.Bool

and then

bool.Value = true / false

then in the script:

local bool = boolPath

if bool.Value == true/false or whatever then
return
else
--run script
end

1 Like

Example of how to do it:

SCRIPT 1

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local PrintScript = script.Parent:WaitForChild("Print")

Mouse.Button1Down:Connect(function()
	print("Player Clicked")
	if PrintScript.Enabled == true then
		PrintScript.Enabled = false
	elseif PrintScript.Enabled == false then
		PrintScript.Enabled = true
	end
end)

OTHERSCRIPT:

while task.wait() do
	print("I am enabled.")
end
2 Likes


alright so i tried that but some reason the values arent being changed?
(also game is capped at 20 fps so my bad if its too laggy)

1 Like

Your script does not recheck the Bool unless you tell it to check.

Try:

bool:GetPropertyChangedSignal(“Value”):Connect(function()
– do stuff
end)

1 Like

well i tried that but the script itself now doesnt work heres what i did

Bool:GetPropertyChangedSignal("Value"):Connect(function()
	Mouse.Button1Down:Connect(function()
		if workspace:FindFirstChild("Location") then
			workspace.Location:Destroy()
		end
		local Part = Instance.new("Part")
		Part.Shape = "Cylinder"
		Part.Size = Vector3.new(0.25, 2, 2)
		Part.Anchored = true
		Part.CanCollide = false
		Part.Orientation = Vector3.new(0,0,-90)
		Part.Parent = workspace
		Part.Position = Mouse.Hit.p
		Part.Name = "Location"
		Part.Material = "Plastic"
		Part.BrickColor = BrickColor.new("Lime green")

		local Character = Player.Character
		Character.Humanoid:MoveTo(Mouse.Hit.p)

		Part.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				Part:Destroy()
			end
		end)
	end)
end)

Just check the value when the mouse button is clicked.

Mouse.Button1Down:Connect(function()
	if bool.Value == true then
		if workspace:FindFirstChild("Location") then
			workspace.Location:Destroy()
		end
		local Part = Instance.new("Part")
		Part.Shape = "Cylinder"
		Part.Size = Vector3.new(0.25, 2, 2)
		Part.Anchored = true
		Part.CanCollide = false
		Part.Orientation = Vector3.new(0,0,-90)
		Part.Parent = workspace
		Part.Position = Mouse.Hit.p
		Part.Name = "Location"
		Part.Material = "Plastic"
		Part.BrickColor = BrickColor.new("Lime green")

		local Character = Player.Character
		Character.Humanoid:MoveTo(Mouse.Hit.p)

		Part.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				Part:Destroy()
			end
		end)	
	end

end)

yeah but the value doesnt change

In your last video you are looking in the StarterGui.

When you press Play in studio that StarterGui is cloned into your PlayerGui in the Players folder.

Look there to see if the value is changing.

what do you mean by that, like are you saying that although the value is set to false for example, the rbxscriptconnection still sees it as true?

i checked and it also doesnt change there

i think so? i dont know what rbxscriptconnection is

this:

Mouse.Button1Down:Connect(function()
	if workspace:FindFirstChild("Location") then
		workspace.Location:Destroy()
	end
	local Part = Instance.new("Part")
	Part.Shape = "Cylinder"
	Part.Size = Vector3.new(0.25, 2, 2)
	Part.Anchored = true
	Part.CanCollide = false
	Part.Orientation = Vector3.new(0,0,-90)
	Part.Parent = workspace
	Part.Position = Mouse.Hit.p
	Part.Name = "Location"
	Part.Material = "Plastic"
	Part.BrickColor = BrickColor.new("Lime green")
	
	local Character = Player.Character
	Character.Humanoid:MoveTo(Mouse.Hit.p)
	
	Part.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			Part:Destroy()
		end
	end)
end)

or basically the function that is being connected to Button1Down.

you didnt change anything? well i changed some stuff now the script does get disabled but somehow it still works? if you want il record a video

I know I didn’t change anything, I want to show you an example of a RBXScriptConnection. So I used your code as an example.

But please do record a video.

ohhh yeah i see anyways heres the video

This is happening because something that disables the script is referencing the StarterGui, which is not the player’s gui.

What’s the script that disables the script according to the value?

yeah i guessed that too i tried it but i probably messed up somewhere so il rewrite it rn

local button = script.Parent
local Bool = script.Parent.Bool
local ClickToMove = game.StarterGui.ClickMove

button.MouseButton1Click:Connect(function()
	if Bool.Value == false then
		button.TextColor3 = Color3.new(1, 0, 0)
		Bool.Value = true
		ClickToMove.Disabled = true
		
	elseif Bool.Value == true then
	button.TextColor3 = Color3.new(0, 1, 0)
		Bool.Value = false
		ClickToMove.Disabled = false
	end
end)

this is the code right now

1 Like

okay so after rewriting it the code just stops working

local button = script.Parent
local Bool = script.Parent.Bool


local ClickToMove = game.Players.LocalPlayer.PlayerGui.ClickMove



button.MouseButton1Click:Connect(function()
	if Bool.Value == false then
		button.TextColor3 = Color3.new(1, 0, 0)
		Bool.Value = true
		ClickToMove.Disabled = true
		
	elseif Bool.Value == true then
	button.TextColor3 = Color3.new(0, 1, 0)
		Bool.Value = false
		ClickToMove.Disabled = false
	end
end)


1 Like

dont u have to set ClickToMove back to true?

1 Like