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

script that supposed to not run when a bool value is true, still runs?

Ok so, in a tool I have a bunch of local scripts, I have 2 scripts one of the Local scripts and inside of it a global script, inside the local script there is a bool value called "Busy" the local script do the fire server thingy on a remote event inside of the global script, the remote event fires only when I say something specific let's say for this case "Aqua eructo" so when I do say that, the local script will fire the remote event fire server and it will set the BoolValue of the local script to false and will set the busy value of all of the other local scripts in the tool to true and then the global script will run it's content but only when I click (I used Activated:wait()) right after that it supposed to check if Bool is true and if it is, it supposed to return end. now the problem is that when I click play on the studio I basically test on the client and when busy is set to true the global script won't run as expected, but in a local server that I have opened when the Boolvalue is true the global script will still run and perform it's contect those are the scripts:

Local script:

local wand = script.Parent
local inc = script.Name
local owner, connect
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Mousehit = Mouse.Hit.p


function Setup()
for i,p in pairs(game.Players:children()) do
if (p.Character == wand.Parent) then
print("Ok123")
if (connect ~= nil) then connect:disconnect() end
connect = p.Chatted:connect(PlayerTalked)
owner = p
end
end
end

function PlayerTalked(words)
print("Someone talked!")
if (string.find(words:lower(), inc:lower()) ~= nil) and (wand.Parent == owner.Character) then
print("Casting...''" ..inc.. "''")
script.Busy.Value = false
script["Aqua eructo"].Disabled = false
script.Done.Value = false
wait()
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA('LocalScript') then
print("it's a local")
local s = v:WaitForChild("Busy")
    if s.ClassName == "BoolValue" and s.Name == "Busy" and s.Parent ~= script then
	print("Horray")
        local Busy = s
        Busy.Value = true
end
    end
end
if owner.Character.Torso:FindFirstChild("Torso") then return end
if owner.Character.Humanoid.JumpPower == 0 then return end
print("Really?")
script["Aqua eructo"].RemoteEvent:FireServer(Mousehit)
end
end
script:WaitForChild("Aqua eructo"):WaitForChild("RemoteFunction").OnClientInvoke = function()
    return owner.Character.Humanoid.TargetPoint
end
wand.Equipped:connect(Setup)

Global script:

script.RemoteEvent.OnServerEvent:connect(function(Player,Mousehit)
Busy = script.Parent:WaitForChild("Busy")
Done = script.Parent:WaitForChild("Done")
if Busy.Value == true then return end
local wand = script.Parent.Parent
local owner, connect
wand.Activated:wait()
if script.Parent.Busy.Value == true then return end
--do stuff--
--all of the "ends" are here--

20 comments

0

connect() is deprecated and so is disconnect(), that might be your problem

0

Then what do I do?

0

capitalize the two methods

0

it's that simple :P

0

Oh alright, let me try this.

0

The global script still runs when the busy value is true on the server.

0

"if Busy.Value == true then break"?

0

or put "return end"/"break" in the code block following the if statement

0

"if script.Parent.Busy.Value == true then return end" I already did that?

0

Break works only in loops I think.

0

Another script that checks if the bool value is true, and accordingly disables the script?

0

I will try that a second.

0

Tried it and it didn't work.

0

Doesn't* it works on the client play option in studio though.

0

You set the value on a localscript; which is local, which means nothing to the server and the server can’t see it. Try using the localscript itself to check for it before firing to the server.

0

What do I need to change on the local script? I am confused, Idk where to put the if statement in the local script to check on the Boolvalue can you help me with that?

0

hold up lemme post the answer

0

Wait I understand what you meant, it is not about the if statment it is about the setting of the other busy values to true and the setting of the boolvalue of the local script to false in the local script itself I need to find a way to do the changes on the server

0

I would like you to do it, thank you.

0

Are you going to upload an answer?

1 answer

✓ Accepted answer

Follow up to my comment: A server cannot check a value that is set locally, so in order to check it, you must use the localscript to check it

Here’s the LocalScript:

local wand = script.Parent
local inc = script.Name
local owner, connect
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Mousehit = Mouse.Hit.p


function Setup()
for i,p in pairs(game.Players:children()) do
if (p.Character == wand.Parent) then
print("Ok123")
if (connect ~= nil) then connect:disconnect() end
connect = p.Chatted:connect(PlayerTalked)
owner = p
end
end
end

function PlayerTalked(words)
print("Someone talked!")
if (string.find(words:lower(), inc:lower()) ~= nil) and (wand.Parent == owner.Character) then
print("Casting...''" ..inc.. "''")
script.Busy.Value = false
script["Aqua eructo"].Disabled = false
script.Done.Value = false
wait()
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA('LocalScript') then
print("it's a local")
local s = v:WaitForChild("Busy")
    if s.ClassName == "BoolValue" and s.Name == "Busy" and s.Parent ~= script then
    print("Horray")
        local Busy = s
        Busy.Value = true
end
    end
end
if owner.Character.Torso:FindFirstChild("Torso") then return end
if owner.Character.Humanoid.JumpPower == 0 then return end
print("Really?")
if not script["Aqua eructo"].Busy.Value then --check if the value is not true then fire the server
script["Aqua eructo"].RemoteEvent:FireServer(Mousehit)
end
end
end
script:WaitForChild("Aqua eructo"):WaitForChild("RemoteFunction").OnClientInvoke = function()
    return owner.Character.Humanoid.TargetPoint
end
wand.Equipped:connect(Setup)

Notice the script["Aqua eructo"].Busy.Value : I assumed your busy value was there so correct that if it wasnt in there.

So just like that your script is fixed. One final step to remove the if check from your server script and you’re all done.

4 comments

0

I will try this.

0

Didn't work, the remoteevent still fires for some reason even in client.

0

Probably because the value is set to false until I say the name of another spell, so it fires the event before it changed to true.

0

I was able to fix it myself, but since your idea really helped me I guess that you brought me a step closer to the right way to fix this, I am accepting this answer.

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