hello, today i am struggling for something. so heres what it is, you press key, and it makes some fake arms to tween forwards, and it looks like your doing tons of punches. the problem is that i for some reason cannot figure out how to get them to delete after 4 seconds… i have tried incorporating debounce, wait(), i just cant figure it out… sorry for the rookie mistake most likely. heres my script for making the arms appear
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local debounce = false
local value = script.Arms
ReplicatedStorage.Remotes.Sunlight_Overdrive.OnServerEvent:Connect(function(player)
value.Value = true
debounce = true
player.Character.Humanoid.WalkSpeed = 8
player.Character.Humanoid.JumpPower = 0
local function makeArms()
while wait(.075) and value.Value == true do
spawn(function()
local leftarm = ReplicatedStorage:FindFirstChild("Effects").LArmWave:Clone()
leftarm.Parent = workspace
leftarm.CFrame = player.Character.LeftHand.CFrame
local TweenService = game:GetService("TweenService")
local goal = {}
goal.CFrame = leftarm.CFrame*CFrame.new(0,0,-5)
local tweenInfo = TweenInfo.new(1)
local tween = TweenService:Create(leftarm, tweenInfo, goal)
tween:Play()
game:GetService("Debris"):AddItem(leftarm,.3)
end)
spawn(function()
local rightarm = ReplicatedStorage:FindFirstChild("Effects").RArmWave:Clone()
rightarm.Parent = workspace
rightarm.CFrame = player.Character.RightHand.CFrame
local TweenService = game:GetService("TweenService")
local goal = {}
goal.CFrame = rightarm.CFrame*CFrame.new(0,0,-5)
local tweenInfo = TweenInfo.new(1)
local tween = TweenService:Create(rightarm, tweenInfo, goal)
tween:Play()
game:GetService("Debris"):AddItem(rightarm,.3)
end)
end
end
makeArms()
wait(4)
value.Value = false
end)
I believe this is because the while loop continues to run and it stops the rest of the script from running. Try putting the while loop inside of the spawn function and see.
Can you show how you edited the script? That solution should definitely fix your problem if implemented properly, so I’m not sure why it’s not working for you.
ReplicatedStorage.Remotes.Sunlight_Overdrive.OnServerEvent:Connect(function(player)
value.Value = true
debounce = true
player.Character.Humanoid.WalkSpeed = 8
player.Character.Humanoid.JumpPower = 0
local function makeArms()
while wait(.075) and value.Value == true do
spawn(function()
while wait(.075) and value.Value == true do
local leftarm = ReplicatedStorage:FindFirstChild("Effects").LArmWave:Clone()
leftarm.Parent = workspace
leftarm.CFrame = player.Character.LeftHand.CFrame
local TweenService = game:GetService("TweenService")
local goal = {}
goal.CFrame = leftarm.CFrame*CFrame.new(0,0,-5)
local tweenInfo = TweenInfo.new(1)
local tween = TweenService:Create(leftarm, tweenInfo, goal)
tween:Play()
game:GetService("Debris"):AddItem(leftarm,.3)
end
end)
spawn(function()
while wait(.075) and value.Value == true do
local rightarm = ReplicatedStorage:FindFirstChild("Effects").RArmWave:Clone()
rightarm.Parent = workspace
rightarm.CFrame = player.Character.RightHand.CFrame
local TweenService = game:GetService("TweenService")
local goal = {}
goal.CFrame = rightarm.CFrame*CFrame.new(0,0,-5)
local tweenInfo = TweenInfo.new(1)
local tween = TweenService:Create(rightarm, tweenInfo, goal)
tween:Play()
game:GetService("Debris"):AddItem(rightarm,.3)
end
end)
end
end
makeArms()
wait(4)
value.Value = false
end)
should i unwrap the spawn functions from the loop?
The suggestion was to put the while loop in the spawn. You still have a loop outside of the spawned function, so it’ll have the exact same issue as before — the loop blocks the code below it from running. Try reverting your code to how it originally was, removing all your spawn calls, and calling spawn(makeArms) instead of makeArms().
Also, I do not suggest that debounce in the server side if the event is fired more than once within the timeframe then the event will be essentially useless. Instead I would make a array of all the players that have fired this event OR you make the debounce local to the serverevent, some developers would just do it on the client but I’d recommend on the server since data such as that doesn’t need to be seen on the client when you can just prevent the server from running the function if the debounce is still in effect.
However I might just be seeing it wrong, you might want it to be fired to the server involving all players not being able to do the same event until the debounce is reset.
the debounce don’t really do anything on the server, never even checks for the debounce being true, this code is copy and pasted from an old project where the debounce does matter. the client has its own system that determines the cooldown for the move