Event doesnt fire

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!

I want to make the event work so when the hitbox touches player it knockbacks them and damages

  1. What is the issue? Include screenshots / videos if possible!
    I even added print statements, and seems like touchedconn event it doesnt work, but for some reason the hitbox.cancollide doesnt set to true too, Idk why.

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried checking if I sent right instances in remote events, and they are

Here’s the Server Script

local rs = game:GetService("ReplicatedStorage")
local rockamount = 1

rs.specialrocks.ice.OnServerEvent:Connect(function(player, magnitude, damage, speed, hitbox, cooldown)
	hitbox.CanCollide = true
	print("c")
	local touchedConn = hitbox.Touched:Connect(function(part)
		print("a")
		if part.Parent.Name ~= player.Name and cooldown.Value == false then
			print("b")
			cooldown.Value = true
			local rockcoins = player.leaderstats.rockcoins
			rockcoins.Value = rockcoins.Value + rockamount
			local hum = part.Parent:FindFirstChild("Humanoid")
			local torso = part.Parent:FindFirstChild("Torso")
			if hum and torso and hum.Health > 0 then
				hum:TakeDamage(damage)
				local char = player.Character or player.CharacterAdded:Wait()
				hum.WalkSpeed = 4
				local facepart = char:FindFirstChild("FacePart")
				local knockback = Instance.new("BodyVelocity")
				knockback.Velocity = facepart.CFrame.LookVector * magnitude
				knockback.P = 5000
				knockback.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
				knockback.Parent = torso
				wait(0.1)
				knockback:Destroy()
			end
			wait(speed)
			hum.WalkSpeed = 16
			cooldown.Value = false
		end
	end)
	hitbox.CanCollide = false
	touchedConn:Disconnect()
end)

And the local script

local tool = script.Parent.Parent
local hitbox = tool.Hitbox
local cooldown = tool:WaitForChild("cooldown")
local rs = game:GetService("ReplicatedStorage")
local damage = 20
local power = 225
local speed = 1

tool.Activated:Connect(function()
	game.ReplicatedStorage.specialrocks.ice:FireServer(power, damage, speed, hitbox, cooldown)
end)

Thanks.

P.S. Only “c” prints

does c print?

Yeah, I forgot to mention that.

It could be the connection.

local rs = game:GetService("ReplicatedStorage")
local rockamount = 1
local touchedConn:RBXScriptConnection?
rs.specialrocks.ice.OnServerEvent:Connect(function(player, magnitude, damage, speed, hitbox, cooldown)
	hitbox.CanCollide = true
	print("c")
	touchedConn = hitbox.Touched:Connect(function(part)
		print("a")
		if part.Parent.Name ~= player.Name and cooldown.Value == false then
			print("b")
			cooldown.Value = true
			local rockcoins = player.leaderstats.rockcoins
			rockcoins.Value = rockcoins.Value + rockamount
			local hum = part.Parent:FindFirstChild("Humanoid")
			local torso = part.Parent:FindFirstChild("Torso")
			if hum and torso and hum.Health > 0 then
				hum:TakeDamage(damage)
				local char = player.Character or player.CharacterAdded:Wait()
				hum.WalkSpeed = 4
				local facepart = char:FindFirstChild("FacePart")
				local knockback = Instance.new("BodyVelocity")
				knockback.Velocity = facepart.CFrame.LookVector * magnitude
				knockback.P = 5000
				knockback.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
				knockback.Parent = torso
				game:GetService("Debris"):AddItem(knockback, 0.1)
			end
			task.wait(speed)
			hitbox.CanCollide = false
			touchedConn:Disconnect()
			hum.WalkSpeed = 16
			cooldown.Value = false
		end
	end)
end)

Thanks! It worked. Could you also explain what you changed and what was the problem because i dont get it?

The connection disconnects immediately, that’s why. you need to disconnect it after the cooldown inside it.

Oh i see, thanks, I will read about debris service :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.