Okay so, I have an a script (A) that makes the status of a BoolValue true, so that other script (B) checks the status of the BoolValue, if the value is true, it’s supposed to disable another script (C) , if the value is false, it makes the script un-disabled. The thing is, it doesn’t seems to work, I have tried searching my problem, but it didn’t help me, I have found something about the script (C) still running so the other script (B) can’t disable it, but i tried to remove Connects and the While true dos, but it still won’t work.
(Sorry if something wasnt clear, i don’t speak english to often)
If you want support with your code, post it.
Anyway you would your want your scripts to look something like this.
Script A
BoolValue.Value = true
Script B
BoolValue.Changed:Connect(function(Value)
ScriptC.Disabled = Value
end)
insane i was struggling with this same thing today i fixed it with a boolvalue and modulescript
If you could provide some of the scripts that would help, I think this could be a copy where you expect a reference situation. If your bool value is used like this
local my_bool_value = game.ServerStorage.BoolValue.Value
Then you are making a copy of the bool value that will never change outside of the script. You need to get a reference by removing the .Value
part of the declaration and using it only when you need to read or write the bool value.
It could also be that disabling scripts prevents the script from running, not stop it in it’s tracks. it will not disconnect connections nor interrupt while loops.
I feel like you shouldn’t need three separate scripts for this, but here we go:
You have ScriptA, ScriptB, and ScriptC. ScriptA communicates with ScriptB via some sort of event. I’m not sure what activates ScriptA, but let’s say it’s a proximity prompt. We have a part that contains ScriptA, the proximity prompt, and your boolValue (although that can be placed anywhere). Once ScriptA changes the value of the boolean, we pickup that change in ScriptB - which then disables or enables ScriptC.
Script A
local boolValue = script.Parent.Value
prompt.Triggered:Connect(function()
--Change Value of boolValue
if boolValue.Value == true then
boolValue.Value = false
else
boolValue.Value = true
end
end)
Script B
local scriptC = workspace.scriptC
local boolValue = workspace.Part.Value
boolValue.Changed:Connect(function(NewValue)
if boolValue.Value == true then
-- enable or disable Script C
scriptC.Disabled = true
else
scriptC.Disabled = false
end
end)
If you’re having a problem with ScriptC, then we’d need to see ScriptC in order to help. We’re not really sure what ScriptC is doing that could be causing the process to fail.
Sorry guys, i totally forgot to share the code.
So, the first script (A) is a tool.
The second second script (B) is the Value checker
the third script (C) is a fist combat system
I don’t have much idea what they since they are free models that i changed a little bit to fit my code
Script A (tool) =
--By Rufus14
wait(0.2)
local tool = script.Parent
local handle = tool.Handle
local remote = tool.RemoteEvent
local players = game:GetService("Players")
local runservice = game:GetService("RunService")
local player = players.LocalPlayer
while task.wait() and not player.Character do end
local character = player.Character
local mouse = player:GetMouse()
local hitboxloop
local state = "unequipped"
local attachments = {}
local hitpeople = {}
local at_lastframe = {}
local ignoreth = {tool, character}
local validatetick = tick()
local registering = false
local multiplehitting = true
local ComDisa = character:FindFirstChild("CombatDisable1").Value
_G.batDEBUG000 = false
function searchforhat(WHATchar)
for q,w in pairs(WHATchar:GetDescendants()) do
if w.Name == "Handle" and w.ClassName == "Part" then
table.insert(ignoreth, w)
end
end
end
function applyspawn(WHO)
WHO.CharacterAppearanceLoaded:Connect(function(WHAT)
searchforhat(WHAT)
end)
end
for i,v in pairs(players:GetPlayers()) do
if v ~= player then
applyspawn(v)
if v.Character then
searchforhat(v.Character)
end
end
end
players.PlayerAdded:Connect(function(WHo)
applyspawn(WHo)
end)
table.foreach(handle:GetChildren(), function(_, a)
if a.ClassName == "Attachment" and a.Name == "hitat" then
a.Changed:Connect(function(WHAT)
if WHAT == "Position" then
a.Parent = nil
end
end)
table.insert(attachments, a)
end
end)
remote.OnClientEvent:Connect(function(WHAT)
if WHAT == "1" then
for i,v in pairs(at_lastframe) do
at_lastframe[i] = nil
end
for i,v in pairs(hitpeople) do
hitpeople[i] = nil
end
registering = true
elseif WHAT == "2" then
registering = false
end
end)
tool.Equipped:Connect(function()
state = "equipped"
if state == "equipped" then
character:FindFirstChild("CombatDisable1").Value = true --this is the value changer
end
validatetick = tick()
player = players.LocalPlayer
character = player.Character
mouse = player:GetMouse()
local frametick = tick()
local delta
hitboxloop = runservice.RenderStepped:Connect(function()
if character:FindFirstChild("Right Arm") then
character["Right Arm"].LocalTransparencyModifier = 0
end
if character:FindFirstChild("Left Arm") then
character["Left Arm"].LocalTransparencyModifier = 0
end
if (workspace.CurrentCamera.CFrame.p - character.Head.Position).magnitude < 1.5 then
character:FindFirstChildOfClass("Humanoid").CameraOffset = Vector3.new(0,0.4,0)
else
character:FindFirstChildOfClass("Humanoid").CameraOffset = Vector3.new(0,0,0)
end
if registering then
delta = tick() - frametick
for i,v in pairs(at_lastframe) do
local ray = Ray.new(v[1].WorldPosition, (v[2] - v[1].WorldPosition).unit*(v[1].WorldPosition - v[2]).magnitude)
local rayhit, raypos = workspace:FindPartOnRayWithIgnoreList(ray, ignoreth)
if rayhit then
local findh = rayhit.Parent:FindFirstChildOfClass("Humanoid")
if findh and findh.Parent ~= character then
if findh.Health > 0 then
if not table.find(hitpeople, findh.Parent) then
if not multiplehitting then
registering = false
end
table.insert(hitpeople, findh.Parent)
remote:FireServer("2", rayhit)
end
end
end
end
if _G.batDEBUG000 then
local p = Instance.new("Part", character)
p.Anchored = true
p.CanCollide = false
p.Material = "Neon"
p.Size = Vector3.new(0.1,0.1,(ray.Origin-raypos).magnitude)
p.CFrame = CFrame.new(ray.Origin, raypos) * CFrame.new(0,0,-(ray.Origin-raypos).magnitude/2)
game.Debris:AddItem(p, 2)
end
at_lastframe[i] = nil
end
table.foreach(attachments, function(_,aa)
table.insert(at_lastframe, {aa, aa.WorldPosition})
end)
frametick = tick()
end
end)
local charhead = character.Head
local charhum = character:FindFirstChildOfClass("Humanoid")
local backuptick = validatetick
while task.wait(0.1) and validatetick == backuptick and state == "equipped" and charhum.Health > 0 do
for i,v in pairs(ignoreth) do
if not v:IsDescendantOf(workspace) then
ignoreth[i] = nil
end
end
remote:FireServer("1", (charhead.Position - mouse.Hit.p).unit.y)
end
end)
tool.Unequipped:Connect(function()
state = "unequipped"
if state == "unequipped" then
character:FindFirstChild("CombatDisable1").Value = false --this is the value changer
end
character:FindFirstChildOfClass("Humanoid").CameraOffset = Vector3.new(0,0,0)
hitboxloop:Disconnect()
end)
Script B (Value checker) =
local player = game:GetService("Players") or game.Players
local lclplr = player.LocalPlayer
local char = lclplr.Character or lclplr.CharacterAdded
local CD = char:WaitForChild("CombatDisable1").Value
local CF = char:WaitForChild("CombatFolder")
local RS = game:GetService("ReplicatedStorage")
if CD == true then
script.Parent.PunchingScript.Disabled = true
elseif CD == false then
script.Parent.PunchingScript.Disabled = false
end
Script C (Fist system) =
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PunchRemote = ReplicatedStorage.Remotes.Punching
local BlockRemote = ReplicatedStorage.Remotes.Blocking
local M2Remote = ReplicatedStorage.Remotes.M2Remote
local Mouse = game.Players.LocalPlayer:GetMouse()
local UserInput = game:GetService("UserInputService")
local Blocking = Character:WaitForChild("Blocking")
local Stunned = Character:WaitForChild("Stunned")
local Block = false
local BlockDebounce = false
local Punched = false
local Combo = 1
local Dmg = false
local CD = script.Parent.Parent:WaitForChild("CombatDisable1").Value
Mouse.Button1Down:Connect(function()
if Stunned.Value == true then return end
if Blocking.Value == true then return end
if Combo == 1 and Punched == false then
Punched = true
PunchRemote:FireServer(Combo)
Combo = Combo + 1
wait(.54) -- change to ur cooldown
Punched = false
elseif Combo == 2 and Punched == false then
Punched = true
PunchRemote:FireServer(Combo)
Combo = Combo + 1
wait(.34)
Punched = false
elseif Combo == 3 and Punched == false then
Punched = true
PunchRemote:FireServer(Combo)
Combo = Combo + 1
wait(.15)
Punched = false
elseif Combo == 4 and Punched == false then
Punched = true
PunchRemote:FireServer(Combo)
Combo = Combo + 1
wait(.85)
Punched = false
elseif Combo == 5 and Punched == false then
Punched = true
PunchRemote:FireServer(Combo)
Combo = 1
wait(4.2)
Punched = false
end
end)
local M2 = false
local M2CoolDown = 2.3
Mouse.Button2Down:Connect(function()
if Stunned.Value == true then return end
if Blocking.Value == true then return end
if M2 == false then
M2 = true
M2Remote:FireServer()
Combo = 1
wait(M2CoolDown)
M2 = false
end
end)
while true do
wait(4)
if Combo ~= 1 and Punched == false then
Combo = 1
end
end
(Sorry if this is a bit messy)
I tried doing this because it maked sense to me, sadly it didn’t work.
If it helps, i saw in the explorer tab for the value inside the local character, it turned on and off whenever the tool was equipped. the script just didn’t disable.
there were two parts to my reply, the first being to modify your B script like so
local CD = char:WaitForChild("CombatDisable1") -- remove .Value from variable declaration
local CF = char:WaitForChild("CombatFolder")
local RS = game:GetService("ReplicatedStorage")
if CD.Value == true then -- use .Value only when you need to
script.Parent.PunchingScript.Disabled = true
elseif CD.Value == false then
script.Parent.PunchingScript.Disabled = false
end
This will use the BoolValue as it changes instead of storing it’s state at the start.
The second part of my reply was that disabling scripts doesn’t disconnect connections, since both your A and C scripts make use of connections even if this was working it probably wouldn’t behave like you want it to. Fixing this could require a rewrite. I would avoid disabling scripts as part of game logic since it’s finicky and not documented well.
Thanks for replying, sadly this didn’t work either, thanks for the help.
Thanks for letting me know about disabling scripts
I managed to make it work by using some Remotes Events, thanks to all people who help me.