Is there a loop that doesn't stop the code below and lets me set values to true or false?

I was trying to make a reload function in my new gun engine and I tried to make it so if you unequip then it stops.

It didn’t work. How do I do it?

1 Like

Could you attach your current code? It will help us see your current method and come up with a new one.

1 Like

local function equip(playa)
local canreload = true
if canreload then
wait(0.15)
game.ReplicatedStorage.MainFolder.Remotes.Send:FireServer(script.Parent.ClipOut)
wait(0.75)
game.ReplicatedStorage.MainFolder.Remotes.Send:FireServer(script.Parent.ClipIn)
wait(0.50)
game.ReplicatedStorage.MainFolder.Remotes.Send:FireServer(script.Parent.ClipHit)
wait(0.50)
game.ReplicatedStorage.MainFolder.Remotes.Send:FireServer(script.Parent.Boltpull)
wait(0.15)
game.ReplicatedStorage.MainFolder.Remotes.Send:FireServer(script.Parent.Boltrelease)
end
end

return equip

1 Like

It’s a module script. The canreload is from the way I tried

1 Like

Here’s the old loop

local function equip(playa)
local CANRELOAD = true
coroutine.wrap(function()
while wait() do
if playa.Character.Equipping.Value == true then
CANRELOAD = false
print(“a”)
end
end
end)()
if CANRELOAD then
wait(0.15)
game.ReplicatedStorage.MainFolder.Remotes.Send:FireServer(script.Parent.ClipOut)
wait(0.75)
game.ReplicatedStorage.MainFolder.Remotes.Send:FireServer(script.Parent.ClipIn)
wait(0.50)
game.ReplicatedStorage.MainFolder.Remotes.Send:FireServer(script.Parent.ClipHit)
wait(0.50)
game.ReplicatedStorage.MainFolder.Remotes.Send:FireServer(script.Parent.Boltpull)
wait(0.15)
game.ReplicatedStorage.MainFolder.Remotes.Send:FireServer(script.Parent.Boltrelease)
else
print(“cmon”)
end
end

return equip