Hello, basically, i made a Character Script that changes a Bool value inside the character.
At the same time, theres a Server Script which detects if the Bool Value is True. If that’s the case, it will start a while loop.
However, the while loop ignores the bool value’s conditions. Likely because the value’s being changed by a Local Script, but i don’t know a good solution to that. How can i set up a good remote event for this? or anything else that can solve it? thanks!
ServerScript
poop = script.Parent:WaitForChild("isrunning")
local sounds = script.Parent:GetChildren()
local filtersnd = {}
for i=1,#sounds do
if sounds[i].Name == "run" then
table.insert(filtersnd, sounds[i])
end
end
while task.wait(0.5) do
if poop.Value == true then
filtersnd[math.random(1,#filtersnd)]:Play()
end
end
Local Script
local humanoid = script.Parent:WaitForChild("Humanoid")
player = script.Parent:WaitForChild("Tors")
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
if humanoid.WalkSpeed ~= 0 then
if humanoid.MoveDirection.Magnitude > 0 then
if player.Waist["Helmet"]["isrunning"].Value == false then
player.Waist["Helmet"]["isrunning"].Value = true
end
else
player.Waist["Helmet"]["isrunning"].Value = false
end
end
end
end)
You’re already firing a remote event to the server to detect when they’re running or not, so just set player.Waist["Helmet"]["isrunning"].Value on the function that receives that remote event.
I’m sorry, but the event is not visible in the screenshot. Also, attach the event triggering and changing the BoolValue to the server script, or just determine the value when the event is fired, and start the loop if the condition is true
You can also do this without BoolValue by using a local variable in the script:
poop = script.Parent:WaitForChild("isrunning")
local Event = script.Parent:FindFirstChild("Event")
local BoolValue = false
local sounds = script.Parent:GetChildren()
local filtersnd = {}
for i=1,#sounds do
if sounds[i].Name == "run" then
table.insert(filtersnd, sounds[i])
end
end
Event.OnServerEvent:Connect(function(Bool)
if Bool == true then
BoolValue = true
elseif Bool == false then
BoolValue = false
end
end)
while task.wait(0.5) do
if BoolValue == true then
filtersnd[math.random(1,#filtersnd)]:Play()
end
end