Why can't I get this old gear to detect it's own bool value?

I’m trying to fix an old gear on Roblox and I ran into this problem where the server script fails to detect the bool value being enabled in the tool by a client script. I know I’m supposed to do something with remote events but I have absolutely no idea where to connect them without breaking the scripts, I did a lot of google searching on how to use remote events but none of them made sense or matched my specific issue. Does anyone here know more about remote events and would be able to fix this for me? Here is an uncopylocked place with the tool I’m trying to fix.

(3) Detect the bool value in this old gear! - Roblox

Or you can just take the model of the tool instead.

(3) Gear that cannot detect it’s own bool value - Roblox

This should be a simple fix, I just have no idea where exactly anything goes. If you manage to get it working then please show me where and how you did it. Thanks and good luck!

The first problem I found is the bool value being enabled in the client script. What happens inside the client script will not be replicated on the server. You will need to use a RemoteEvent to let the server know you have changed a bool value inside the tool. Now if the bool value is created inside the client script, that bool value can be seen client side, but not the server side. That also will require you to fire a RemoteEvent when creating the bool value.

That’s what I thought, but the question is. How can I fire the RemoteEvent when the bool value is enabled from a client script? That’s what I’m trying to do.

I would make a server script for RemoteEvents and do all the coding there. First, create a Remote Event instance inside ReplicatedStorage. Then fire that Remote Event inside the client script. From the Remote Event server script, do all the coding from there such as changing the value of the boolean of the tool. You can pass the tool through the remote event and use that parameter to change the boolean inside the tool.

I’m lost again, I need a better example.

First, make a RemoteEvent inside ReplicatedStorage
Second, inside your client script, fire that RemoteEvent
Third, have a server script that will receive that information
Last, change the bool value using the server script.

Basically what I am trying to say is, do most of your changes in terms of values inside the server script.

Could you show me an example code? Sorry, I’m just really bad at understanding RemoteEvents…

--Client Script
remoteEvent:FireServer() -- sends signal to the remote event

--Server Script
remoteEvent.OnServerEvent:Connect(function() -- receiver end of the remote event
     bool.Value = false
end)

This is how the server and client communicate whenever a value is changed through a client script. For the server to recognize the change, you must do it through RemoteEvents. This is to prevent exploitable hacks that hackers would use to cheat in your game.

More info here: RemoteEvent | Roblox Creator Documentation

So like this?

–ClientScript
local Tool = script.Parent;

enabled = true
function onButton1Down(mouse)
remoteEvent:FireServer()
Tool.WitchGas.Value = true
if not enabled then
return
end

–Server Script
remoteEvent.OnServerEvent:Connect(function()
bool.Value = false
if Tool.WitchGas.Value == true then
print(“VALUE DETECTED”)

Tool.WitchGas.Value = true

This should be done inside the Server Script.

bool.Value = false
if Tool.WitchGas.Value == true then

The if statement would always return false if you make the value false before the comparison. Check to see what the boolean is before changing the value.

The server script got a few errors after I inserted that in, also what else do I do to the client script?

You only need to fire the remote event inside the client script.

Paste this into your server script and help me close those red errors.

local Tool = script.Parent

local broomMode = 1

function broomSetA()
Tool.GripForward = Vector3.new(0,-1,0)
Tool.GripPos = Vector3.new(1.5,-3.5,0)
–Tool.GripPos = Vector3.new(10,10,0)
Tool.GripRight = Vector3.new(1,0,0)
Tool.GripUp = Vector3.new(0,0,-1)
end

function broomSetB()
–Tool.GripForward = Vector3.new(0,0,-1)
–Tool.GripPos = Vector3.new(-1.5,2,1)
–Tool.GripRight = Vector3.new(1,0,0)
–Tool.GripUp = Vector3.new(0,1,0)

Tool.GripForward = Vector3.new(0,-1,0)
Tool.GripPos = Vector3.new(1.5,-3.5,0)
Tool.GripRight = Vector3.new(0,0,1)
Tool.GripUp = Vector3.new(1,0,0)

end

function broomReset()
print(“broom reset”)
Tool.GripForward = Vector3.new(0,-1,0)
Tool.GripPos = Vector3.new(0,0,-1)
Tool.GripRight = Vector3.new(1,0,0)
Tool.GripUp = Vector3.new(0,0,1)
end

broomReset()

Tool.Enabled = true
local started = false
function onActivated()
vCharacter = Tool.Parent
if vCharacter == nil then return end
local vPlayer = game.Players:GetPlayerFromCharacter(vCharacter)
if vPlayer == nil then return end
local humanoid = vCharacter:FindFirstChild(“Humanoid”)
if humanoid == nil then return end

if not Tool.Enabled or humanoid.Jump then return end
Tool.Enabled = false
started = true
local magicSound = Tool.Handle:FindFirstChild("MagicSound")
if magicSound == nil then
	magicSound = Instance.new("Sound")
	magicSound.Parent = Tool.Handle
	magicSound.Volume = 1
	magicSound.SoundId = "http://www.roblox.com/asset/?id=35886425"
	--  35889747  is witch cackle
	--  35886425 is flying noise
	magicSound.Name = "MagicSound"
end
magicSound:Play()

if not started then wait(2) Tool.Enabled = true return end

local newBF = vCharacter.PrimaryPart:FindFirstChild("WitchLift")
if newBF == nil then
	newBF = Instance.new("BodyPosition")
	newBF.position = vCharacter.PrimaryPart.Position + Vector3.new(0,20,0)
	newBF.Parent = vCharacter.PrimaryPart
	newBF.maxForce = Vector3.new(0, 10000, 0)
	newBF.P = 5000
	newBF.Name = "WitchLift"
	-- maxForce (vector), P(number), D(number)
end
--humanoid.Jump = true

if not started then wait(2) Tool.Enabled = true return end

wait(1)
--newBF.maxForce = Vector3.new(30000,10000,30000)
newBF.maxForce = Vector3.new(50000,30000,50000)
--humanoid.Jump = true
broomSetA()
--broomMode = 1


-- if started then Tool.Handle.CanCollide = false end

if not started then wait(2) Tool.Enabled = true return end

local fakeBroom = Tool.Handle:Clone()
Tool.Handle.Transparency = 1
fakeBroom.Mesh.Scale = Vector3.new(2.2,2.2,2.2)
fakeBroom.Parent = vCharacter
fakeBroom.Name = "myBroom"
	
local broomWeld = Instance.new("Weld")
broomWeld.Part0 = fakeBroom
broomWeld.Part1 = vCharacter.HumanoidRootPart
broomWeld.C0 = fakeBroom.CFrame:inverse()*vCharacter.HumanoidRootPart.CFrame
broomWeld.Name = "BroomWeld"
broomWeld.Parent = vCharacter

if not started then wait(2) Tool.Enabled = true return end

magicSound.Looped = true
magicSound:Play()

local witchSound = Tool.Handle:FindFirstChild("WitchSound")
if witchSound == nil then
	witchSound = Instance.new("Sound")
	witchSound.Parent = Tool.Handle
	witchSound.Volume = 1
	witchSound.SoundId = "http://www.roblox.com/asset/?id=35889747"
	witchSound.Name = "WitchSound"
end
witchSound.Looped = false
witchSound:Play()

local flightTime = 5
if vPlayer.Backpack:FindFirstChild("WitchWand") ~= nil then flightTime = flightTime + 3 end
if vPlayer.Backpack:FindFirstChild("WitchCauldron") ~= nil then flightTime = flightTime + 3 end
if vCharacter:FindFirstChild("WhiteWitchHat") ~= nil then flightTime = flightTime + 5
elseif vCharacter:FindFirstChild("WitchHat") ~= nil then flightTime = flightTime + 5 end

if not started then wait(2) Tool.Enabled = true return end

for i = 1, flightTime*10 do
	if humanoid ~= nil then humanoid.Jump = true end
		newBF = vCharacter.PrimaryPart:FindFirstChild("WitchLift")
		if newBF == nil then
			humanoid.Jump = true
			Tool.Enabled = true
		newBG = vCharacter.HumanoidRootPart:FindFirstChild("WitchWay")
			if newBG ~= nil then newBG.Parent = nil end
			return 
		end
	local lookAt = humanoid.TargetPoint - vCharacter.PrimaryPart.Position
	remoteEvent.OnServerEvent:Connect(function()
		bool.Value = false
		if Tool.WitchGas.Value == true then
			print("VALUE DETECTED")
		newBF.position = newBF.position + lookAt.unit*10 
		magicSound:Play()
	else magicSound:Stop()
	end

	
	newBG = vCharacter.HumanoidRootPart:FindFirstChild("WitchWay")
	if newBG == nil then
		newBG = Instance.new("BodyGyro")
		newBG.Parent = vCharacter.HumanoidRootPart
		newBG.Name = "WitchWay"
		newBG.maxTorque = Vector3.new(50000,50000,50000)
	end
	newBG.cframe = CFrame.new(vCharacter.HumanoidRootPart.Position, vCharacter.HumanoidRootPart.Position + lookAt.unit)
end 

broomReset()

newBG = vCharacter.HumanoidRootPart:FindFirstChild("WitchWay")
if newBG ~= nil then newBG.Parent = nil end

magicSound = Tool.Handle:FindFirstChild("MagicSound")
if magicSound ~= nil then
	magicSound.Looped = false
	magicSound:Stop()
end
witchSound = Tool.Handle:FindFirstChild("WitchSound")
if witchSound ~= nil then
	witchSound.Looped = false
	witchSound:Stop()
end

broomWeld = vCharacter:FindFirstChild("BroomWeld")
if broomWeld ~= nil then
	broomWeld.Parent = nil
	fakeBroom.Parent = nil
end
fakeBroom = vCharacter:FindFirstChild("myBroom")
if fakeBroom ~= nil then
	fakeBroom.Parent = nil
end

Tool.Handle.Transparency = 0

Tool.Handle.CanCollide = true
newBF.Parent = nil
humanoid.Jump = true
Tool.Enabled = true

end

function onEquipped()
broomReset()
–Tool.Handle.CanCollide = false
local magicSound = Tool.Handle:FindFirstChild(“MagicSound”)
if magicSound == nil then
magicSound = Instance.new(“Sound”)
magicSound.Parent = Tool.Handle
magicSound.Volume = 1
magicSound.SoundId = “http://www.roblox.com/asset/?id=35886425
– 35889747 is witch cackle
– 35886425 is flying noise
magicSound.Name = “MagicSound”
end
local witchSound = Tool.Handle:FindFirstChild(“WitchSound”)
if witchSound == nil then
witchSound = Instance.new(“Sound”)
witchSound.Parent = Tool.Handle
witchSound.Volume = 1
witchSound.SoundId = “http://www.roblox.com/asset/?id=35889747
witchSound.Name = “WitchSound”
end
end

function onUnequipped()
Tool.Handle.CanCollide = true
started = false
broomReset()
local broomWeld = vCharacter:FindFirstChild(“BroomWeld”)
if broomWeld ~= nil then
broomWeld.Parent = nil
end
local fakeBroom = vCharacter:FindFirstChild(“myBroom”)
if fakeBroom ~= nil then
fakeBroom.Parent = nil
end

newBG = vCharacter.HumanoidRootPart:FindFirstChild("WitchWay")
	if newBG ~= nil then newBG.Parent = nil end
	local magicSound = Tool.Handle:FindFirstChild("MagicSound")
	local witchSound = Tool.Handle:FindFirstChild("WitchSound")
	if magicSound ~= nil then
		magicSound:Stop()
		magicSound.Parent = nil
	end
	if witchSound ~= nil then
		witchSound:Stop()
		witchSound.Parent = nil
	end
	local newBF = vCharacter.PrimaryPart:FindFirstChild("WitchLift")
	if newBF ~= nil then newBF.Parent = nil end

	Tool.Handle.Transparency = 0
	Tool.Handle.CanCollide = true

end

Tool.Activated:connect(onActivated)
Tool.Equipped:connect(onEquipped)
Tool.Unequipped:connect(onUnequipped)

I can’t close the errors, I need help!

I think I removed the red dotted lines but this prints in the output
image

Make a new remote event on the tool.
On the localscript do this

function onButton1Down(mouse)
	EVENTHERE:FireServer("ON") -- an argument to make the value true
end
function onButton1Up(mouse)
	EVENTHERE:FireServer("OFF")
end
--SERVERSCRIPT
EVENTHERE.OnServerEvent:Connect(function(fakeplayer, state)
  if state == "ON" then
     Tool.WitchGas.Value = true 
  else
     Tool.WitchGas.Value = false
  end
end)

Can you give me the full server script? Every time I try to put it in myself I get a bunch of red dotted errors.






--ATTENTION!!!

--THE PROBLEM IS LOCATED AT LINE 156












local Tool = script.Parent
local EVENTHERE = Tool:WaitForChild("your new event")
EVENTHERE.OnServerEvent:Connect(function(fakeplayer, state)
  if state == "ON" then
     Tool.WitchGas.Value = true 
  else
     Tool.WitchGas.Value = false
  end
end)

local broomMode = 1

function broomSetA()
	Tool.GripForward = Vector3.new(0,-1,0)
	Tool.GripPos = Vector3.new(1.5,-3.5,0)
	--Tool.GripPos = Vector3.new(10,10,0)
	Tool.GripRight = Vector3.new(1,0,0)
	Tool.GripUp = Vector3.new(0,0,-1)
end

function broomSetB()
	--Tool.GripForward = Vector3.new(0,0,-1)
	--Tool.GripPos = Vector3.new(-1.5,2,1)
	--Tool.GripRight = Vector3.new(1,0,0)
	--Tool.GripUp = Vector3.new(0,1,0)

	Tool.GripForward = Vector3.new(0,-1,0)
	Tool.GripPos = Vector3.new(1.5,-3.5,0)
	Tool.GripRight = Vector3.new(0,0,1)
	Tool.GripUp = Vector3.new(1,0,0)
end

function broomReset()
	print("broom reset")
	Tool.GripForward = Vector3.new(0,-1,0)
	Tool.GripPos = Vector3.new(0,0,-1)
	Tool.GripRight = Vector3.new(1,0,0)
	Tool.GripUp = Vector3.new(0,0,1)
end

broomReset()

Tool.Enabled = true
local started = false
function onActivated()
	vCharacter = Tool.Parent
	if vCharacter == nil then return end
	local vPlayer = game.Players:GetPlayerFromCharacter(vCharacter)
	if vPlayer == nil then return end
	local humanoid = vCharacter:FindFirstChild("Humanoid")
	if humanoid == nil then return end
	
	if not Tool.Enabled or humanoid.Jump then return end
	Tool.Enabled = false
	started = true
	local magicSound = Tool.Handle:FindFirstChild("MagicSound")
	if magicSound == nil then
		magicSound = Instance.new("Sound")
		magicSound.Parent = Tool.Handle
		magicSound.Volume = 1
		magicSound.SoundId = "http://www.roblox.com/asset/?id=35886425"
		--  35889747  is witch cackle
		--  35886425 is flying noise
		magicSound.Name = "MagicSound"
	end
	magicSound:Play()
	
	if not started then wait(2) Tool.Enabled = true return end

	local newBF = vCharacter.PrimaryPart:FindFirstChild("WitchLift")
	if newBF == nil then
		newBF = Instance.new("BodyPosition")
		newBF.position = vCharacter.PrimaryPart.Position + Vector3.new(0,20,0)
		newBF.Parent = vCharacter.PrimaryPart
		newBF.maxForce = Vector3.new(0, 10000, 0)
		newBF.P = 5000
		newBF.Name = "WitchLift"
		-- maxForce (vector), P(number), D(number)
	end
	--humanoid.Jump = true

	if not started then wait(2) Tool.Enabled = true return end

	wait(1)
	--newBF.maxForce = Vector3.new(30000,10000,30000)
	newBF.maxForce = Vector3.new(50000,30000,50000)
	--humanoid.Jump = true
	broomSetA()
	--broomMode = 1


	-- if started then Tool.Handle.CanCollide = false end

	if not started then wait(2) Tool.Enabled = true return end

	local fakeBroom = Tool.Handle:Clone()
	Tool.Handle.Transparency = 1
	fakeBroom.Mesh.Scale = Vector3.new(2.2,2.2,2.2)
	fakeBroom.Parent = vCharacter
	fakeBroom.Name = "myBroom"
		
	local broomWeld = Instance.new("Weld")
	broomWeld.Part0 = fakeBroom
	broomWeld.Part1 = vCharacter.HumanoidRootPart
	broomWeld.C0 = fakeBroom.CFrame:inverse()*vCharacter.HumanoidRootPart.CFrame
	broomWeld.Name = "BroomWeld"
	broomWeld.Parent = vCharacter

	if not started then wait(2) Tool.Enabled = true return end

	magicSound.Looped = true
	magicSound:Play()

	local witchSound = Tool.Handle:FindFirstChild("WitchSound")
	if witchSound == nil then
		witchSound = Instance.new("Sound")
		witchSound.Parent = Tool.Handle
		witchSound.Volume = 1
		witchSound.SoundId = "http://www.roblox.com/asset/?id=35889747"
		witchSound.Name = "WitchSound"
	end
	witchSound.Looped = false
	witchSound:Play()

	local flightTime = 5
	if vPlayer.Backpack:FindFirstChild("WitchWand") ~= nil then flightTime = flightTime + 3 end
	if vPlayer.Backpack:FindFirstChild("WitchCauldron") ~= nil then flightTime = flightTime + 3 end
	if vCharacter:FindFirstChild("WhiteWitchHat") ~= nil then flightTime = flightTime + 5
	elseif vCharacter:FindFirstChild("WitchHat") ~= nil then flightTime = flightTime + 5 end

	if not started then wait(2) Tool.Enabled = true return end

	for i = 1, flightTime*10 do
		if humanoid ~= nil then humanoid.Jump = true end
			newBF = vCharacter.PrimaryPart:FindFirstChild("WitchLift")
			if newBF == nil then
				humanoid.Jump = true
				Tool.Enabled = true
			newBG = vCharacter.HumanoidRootPart:FindFirstChild("WitchWay")
				if newBG ~= nil then newBG.Parent = nil end
				return 
			end
		local lookAt = humanoid.TargetPoint - vCharacter.PrimaryPart.Position
		if Tool.WitchGas.Value == true then --THIS SCRIPT DOESN'T KNOW THAT THE VALUE IS TRUE!
			print("VALUE DETECTED") --IF THIS PRINTS THAT MEANS THE SCRIPT SUCCESSFULLY DETECTED THE VALUE LIKE IT WAS SUPPOSED TO DO...
			newBF.position = newBF.position + lookAt.unit*10 
			magicSound:Play()
		else magicSound:Stop()
		end

		
		newBG = vCharacter.HumanoidRootPart:FindFirstChild("WitchWay")
		if newBG == nil then
			newBG = Instance.new("BodyGyro")
			newBG.Parent = vCharacter.HumanoidRootPart
			newBG.Name = "WitchWay"
			newBG.maxTorque = Vector3.new(50000,50000,50000)
		end
		newBG.cframe = CFrame.new(vCharacter.HumanoidRootPart.Position, vCharacter.HumanoidRootPart.Position + lookAt.unit)
	end 

	broomReset()

	newBG = vCharacter.HumanoidRootPart:FindFirstChild("WitchWay")
	if newBG ~= nil then newBG.Parent = nil end

	magicSound = Tool.Handle:FindFirstChild("MagicSound")
	if magicSound ~= nil then
		magicSound.Looped = false
		magicSound:Stop()
	end
	witchSound = Tool.Handle:FindFirstChild("WitchSound")
	if witchSound ~= nil then
		witchSound.Looped = false
		witchSound:Stop()
	end

	broomWeld = vCharacter:FindFirstChild("BroomWeld")
	if broomWeld ~= nil then
		broomWeld.Parent = nil
		fakeBroom.Parent = nil
	end
	fakeBroom = vCharacter:FindFirstChild("myBroom")
	if fakeBroom ~= nil then
		fakeBroom.Parent = nil
	end

	Tool.Handle.Transparency = 0

	Tool.Handle.CanCollide = true
	newBF.Parent = nil
	humanoid.Jump = true
	Tool.Enabled = true
end


function onEquipped()
	broomReset()
	--Tool.Handle.CanCollide = false
	local magicSound = Tool.Handle:FindFirstChild("MagicSound")
	if magicSound == nil then
		magicSound = Instance.new("Sound")
		magicSound.Parent = Tool.Handle
		magicSound.Volume = 1
		magicSound.SoundId = "http://www.roblox.com/asset/?id=35886425"
		--  35889747  is witch cackle
		--  35886425 is flying noise
		magicSound.Name = "MagicSound"
	end
	local witchSound = Tool.Handle:FindFirstChild("WitchSound")
	if witchSound == nil then
		witchSound = Instance.new("Sound")
		witchSound.Parent = Tool.Handle
		witchSound.Volume = 1
		witchSound.SoundId = "http://www.roblox.com/asset/?id=35889747"
		witchSound.Name = "WitchSound"
	end
end

function onUnequipped()
		Tool.Handle.CanCollide = true
		started = false
		broomReset()
		local broomWeld = vCharacter:FindFirstChild("BroomWeld")
		if broomWeld ~= nil then
			broomWeld.Parent = nil
		end
		local fakeBroom = vCharacter:FindFirstChild("myBroom")
		if fakeBroom ~= nil then
			fakeBroom.Parent = nil
		end

	newBG = vCharacter.HumanoidRootPart:FindFirstChild("WitchWay")
		if newBG ~= nil then newBG.Parent = nil end
		local magicSound = Tool.Handle:FindFirstChild("MagicSound")
		local witchSound = Tool.Handle:FindFirstChild("WitchSound")
		if magicSound ~= nil then
			magicSound:Stop()
			magicSound.Parent = nil
		end
		if witchSound ~= nil then
			witchSound:Stop()
			witchSound.Parent = nil
		end
		local newBF = vCharacter.PrimaryPart:FindFirstChild("WitchLift")
		if newBF ~= nil then newBF.Parent = nil end

		Tool.Handle.Transparency = 0
		Tool.Handle.CanCollide = true
end

Tool.Activated:connect(onActivated)
Tool.Equipped:connect(onEquipped)
Tool.Unequipped:connect(onUnequipped)

It kinda works, the broom stops flying after it takes off though. Can you send me the client script as well?

This is what it looks like on my end, the value is detected but something is messing with the flight duration. https://i.gyazo.com/ffc309f347bc4b9a15a61bb833c35ca0.mp4