How to fire a remote event constantly, and after a couple of seconds, stop firing it

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    (explained in topic), kind of like The Strongest Battlegrounds 20-20-20 dropkick move

  2. What is the issue? Include screenshots / videos if possible!
    image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i have tried using renderstepped, a repet loop a for loop and nothing worked, and i also looked for answers on developer hub but i couldnt find anything related to my topic

3 Likes
local func = game["RunService"].RenderStepped:Connect(function()
game.ReplicatedStorage.Remote:FireServer()
wait(.5)--Amount of time
end)
game.ReplicatedStorage.AnimRemote.OnclientEvent:Connect(function()
func:Disconnect()
end)
2 Likes

remote doesnt fire every 1/2 seconds

heres how i adapted it to my script
image

2 Likes

Sorry you don’t need task.wait in a RenderStepped loop, try removing it and see if it works.

1 Like

still no
image

1 Like

That’s really weird, maybe try putting the disconnect at the beginning.

same thing as before, also it doesnt give errors

1 Like

Heres the full code:

wait(.1)

local cd = 2
local db = false
local canDropKick = false

local humanoid = game.Players.LocalPlayer.Character:FindFirstChildWhichIsA(“Humanoid”)
local uis = game:GetService(“UserInputService”)

local start = script:WaitForChild(“Fail”)
local startTrack = humanoid:LoadAnimation(start)

humanoid.UseJumpPower = true

uis.InputBegan:Connect(function(k, gpe)
if k.KeyCode == Enum.KeyCode.Two and not gpe and db == false then
db = true
startTrack:Play()

	humanoid.WalkSpeed = 0
	
	local bv = Instance.new("LinearVelocity")
	
	startTrack:GetMarkerReachedSignal("Dash"):Connect(function()
		print('Hit')
		
		humanoid.Parent.HumanoidRootPart.RootAttachment.Rotation = Vector3.new(0, 90, 0)
		
		game.ReplicatedStorage.DropkickRemote:FireServer()
		
		bv.Parent = humanoid.Parent.HumanoidRootPart
		bv.MaxForce = 20000
		bv.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
		bv.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
		bv.Attachment0 = humanoid.Parent.HumanoidRootPart.RootAttachment
		bv.LineVelocity = 20000
		
		canDropKick = true
	end)
	
	local func = game["RunService"].RenderStepped:Connect(function()
		game.ReplicatedStorage.DropkickRemote:FireServer()
	end)
	
	game.ReplicatedStorage.DropkickAnimRemote.OnClientEvent:Connect(function()
		func:Disconnect()
		startTrack:Stop()
		game.Debris:AddItem(bv, 0)
	end)
	
	startTrack:GetMarkerReachedSignal("Fail"):Connect(function()
		game.Debris:AddItem(bv, 0)
		canDropKick = false
	end)
	
	wait(startTrack.Length)
	
	humanoid.WalkSpeed = 16
	
	wait(cd)
	db = false
end

end)

– I changed remote to dropkickremote

1 Like

try this

var = true
while task.wait(.5) and var == true do
	print("Event Fired")
	game.ReplicatedStorage.AnimRemote.OnClientEvent:Connect(function()
		var = false
		print("Stopped")
	end)
end


1 Like

still no

heres the full script again:
wait(.1)

local cd = 2
local db = false
local canDropKick = false

local humanoid = game.Players.LocalPlayer.Character:FindFirstChildWhichIsA(“Humanoid”)
local uis = game:GetService(“UserInputService”)

local start = script:WaitForChild(“Fail”)
local startTrack = humanoid:LoadAnimation(start)

humanoid.UseJumpPower = true

uis.InputBegan:Connect(function(k, gpe)
if k.KeyCode == Enum.KeyCode.Two and not gpe and db == false then
db = true
startTrack:Play()

	humanoid.WalkSpeed = 0
	
	local bv = Instance.new("LinearVelocity")
	
	startTrack:GetMarkerReachedSignal("Dash"):Connect(function()
		print('Hit')
		
		humanoid.Parent.HumanoidRootPart.RootAttachment.Rotation = Vector3.new(0, 90, 0)
		
		game.ReplicatedStorage.DropkickRemote:FireServer()
		
		bv.Parent = humanoid.Parent.HumanoidRootPart
		bv.MaxForce = 20000
		bv.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
		bv.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
		bv.Attachment0 = humanoid.Parent.HumanoidRootPart.RootAttachment
		bv.LineVelocity = 20000
	end)
	
	canDropKick = true
	
	while task.wait(.5) and canDropKick == true do
		game.ReplicatedStorage.DropkickRemote:FireServer()
		game.ReplicatedStorage.AnimRemote.OnClientEvent:Connect(function()
			canDropKick = false
			print("Stopped")
			startTrack:Stop()
			game.Debris:AddItem(bv, 0)
		end)
	end
	
	startTrack:GetMarkerReachedSignal("Fail"):Connect(function()
		game.Debris:AddItem(bv, 0)
		canDropKick = false
	end)
	
	wait(startTrack.Length)
	
	humanoid.WalkSpeed = 16
	
	wait(cd)
	db = false
end

end)

1 Like

can you specify what you need this to do

Using a loop to fire a remote event is bad practice, Im guessing you’re using it to make the Animation longer. Am I hearing this right?

1 Like

i want it to fire a remote consistantly so that it can play like a cutscene/animation, and if you fail to hit an opponent between a time frame then stop firing the remote (basically explained in topic)

no, there was already a renderstepped function on the script that did the work for me, but when you hit the opponent, it becomes super laggy, the animation isnt played correctly and it still fires the event

I think it’d be best to fire a remote when you fail to hit rather than sending alot of them. It’s easier on the network and scripting

remote:FireServe(true) -- true for failed
-- server

remote.OnServerEvent:Connect(function(player, failed)
-- make sure the player is doing this action
if failed then
-- failed logic

return
end

-- other logic
end)

actually, it’d be best to just check how long it takes you to fire the hit remote on the server

1 Like

Make it so it plays the animation while the player is in the dropkick state. If the time ran out or the player hit another, then stop the animation and deal damage.

but this doesnt make it so you are able to hit the opponent mid-animation

1 Like

oh but it does. just dont give the remote the failed parameter

remote:FireServer() – successful hit

remote:FireServer(true) – failed hit

1 Like

heres both scripts (only essential parts):

startTrack:GetMarkerReachedSignal(“Dash”):Connect(function()
print(‘Hit’)

		humanoid.Parent.HumanoidRootPart.RootAttachment.Rotation = Vector3.new(0, 90, 0)
		
		game.ReplicatedStorage.DropkickRemote:FireServer()
		
		bv.Parent = humanoid.Parent.HumanoidRootPart
		bv.MaxForce = 20000
		bv.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
		bv.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
		bv.Attachment0 = humanoid.Parent.HumanoidRootPart.RootAttachment
		bv.LineVelocity = 20000
	end)
	
	game.ReplicatedStorage.DropkickAnimRemote.OnClientEvent:Connect(function()
		canDropKick = false
		print("Stopped")
		startTrack:Stop()
		game.Debris:AddItem(bv, 0)
	end)
	
	startTrack:GetMarkerReachedSignal("Fail"):Connect(function()
		game.Debris:AddItem(bv, 0)
		canDropKick = false
		game.ReplicatedStorage.DropkickRemote:FireServer(true)
	end)

script (server):

event.OnServerEvent:Connect(function(player, failed)
if failed == true then return end

local char = player.Character
local attackingPart = "Torso"

local hbClone = hitbox:Clone()
hbClone.Parent = workspace

local hbCFrame = char[attackingPart].CFrame

hbClone.CFrame = hbCFrame

local weld = Instance.new("WeldConstraint", hbClone)
weld.Part0 = hbClone
weld.Part1 = char[attackingPart]

local chars = {}

for _, part in pairs(GetTouchingParts(hbClone)) do
	local eChar = part.Parent
	
	if table.find(chars, eChar) == nil and eChar ~= char then
		local humanoid = eChar:FindFirstChild("Humanoid")
	
		if humanoid ~= nil then
			table.insert(chars, eChar)
		end
	end
end

print(chars)

hbClone:Destroy()

for _, enemyChar in pairs(chars) do
	local enemyHumanoid = enemyChar:FindFirstChildWhichIsA("Humanoid")
	local humanoid = char:FindFirstChildWhichIsA("Humanoid")
	
	local playingTracks = humanoid:GetPlayingAnimationTracks()
	
	for _, track in pairs(playingTracks) do
		track:Stop()
		
		enemyHumanoid.Parent.HumanoidRootPart.Anchored = true
		humanoid.Parent.HumanoidRootPart.Anchored = true
		
		game.ReplicatedStorage.DropkickAnimRemote:FireClient(player)
		
		enemyHumanoid.WalkSpeed = 0
		humanoid.WalkSpeed = 0
		
		local enemyAnimation = Instance.new("Animation")
		enemyAnimation.AnimationId = "rbxassetid://18136825007"
		
		local animation = Instance.new("Animation")
		animation.AnimationId = "rbxassetid://18136827701"
		
		local enemyTrack = enemyHumanoid:LoadAnimation(enemyAnimation)
		enemyTrack:Play()
		
		local animationTrack = humanoid:LoadAnimation(animation)
		animationTrack:Play()
		
		animationTrack:GetMarkerReachedSignal("End"):Connect(function()
			enemyHumanoid:TakeDamage(13278971839219)
		end)
		
		animationTrack:GetMarkerReachedSignal("End"):Connect(function()
			humanoid.WalkSpeed = 16
			humanoid.Parent.HumanoidRootPart.Anchored = false
		end)
		
		enemyTrack:GetMarkerReachedSignal("End"):Connect(function()
			local motors = ragdollModule.CreateJoints(enemyChar)
			ragdollModule.Ragdoll(enemyChar)
			ragdollModule.SetMotorsEnabled(motors, false)
			
			task.delay(2, function()
				ragdollModule.DestroyJoints(enemyChar)
				ragdollModule.SetMotorsEnabled(motors, true)
				ragdollModule.UnRagdoll(enemyChar)
			end)
		end)
	end
end

end)

i still dont understand what your trying to say because it fires only once

2 Likes

Well you arent trying understand the solution im giving you.
Re read what i said as im not going to write the entire thing for you