Remote Event not firing

So I am trying to fire a remote event when the projectile hits the enemy but it doesn’t seem to fire.

Client:

local Debris = game:GetService("Debris")

local part = script.Parent

local ZombiesFolder = workspace:WaitForChild("ZombiesFolder")

local isHit = false

local despawnTime = 4

local function Damage(hit)
	local character = hit:FindFirstAncestorWhichIsA("Model")
	
	if character then
		script.DamageTarget:FireServer(hit) -- not firing
		part:Destroy()
	end
end

part.Touched:Connect(function(hit)
	if hit:IsDescendantOf(ZombiesFolder) and not isHit then
		isHit = true
		Damage(hit)
	end
end)

Debris:AddItem(part, despawnTime)

Server:

local damage = 10

local function Damage(hit)
	local character = hit:FindFirstAncestorWhichIsA("Model")

	if character then
		local humanoid = character:FindFirstChildOfClass("Humanoid")

		if humanoid then
			humanoid:TakeDamage(damage)
		end
	end
end

script.Parent.DamageTarget.OnServerEvent:Connect(function(player, hit)
	
	print(hit) -- nothing
	
	if hit then
		Damage(hit)
	end
end)

image
The client script enables when shot.

2 Likes

I think I know what the cause is.

Could you provide the whole hierarchical “system”?

1 Like

RemoteEvents need to be in ReplicatedStorage for both the server and client to be able to use it.

1 Like

The weapon handler: (client)

local function Shoot(target)
	local result = PlayShootAnimation()

	if result then
		local newProjectile = Projectile:Clone()
		newProjectile.CFrame = ShootPart.CFrame

		local attachment = Instance.new("Attachment")
		attachment.Parent = newProjectile

		local LinearVelocity = Instance.new("LinearVelocity")
		LinearVelocity.Attachment0 = attachment
		LinearVelocity.MaxForce = math.huge
		LinearVelocity.RelativeTo = Enum.ActuatorRelativeTo.World
		LinearVelocity.VectorVelocity = ShootPart.CFrame.LookVector * projectileSpeed
		LinearVelocity.Parent = newProjectile

		newProjectile.Parent = ProjectilesFolder
		newProjectile.Handler.Enabled = true -- enables the local script
	end
end

RunService.Heartbeat:Connect(function()
	local nearestTarget, nearestDistance = GetNearestZombieInRow()

	if nearestTarget ~= nil and nearestDistance ~= nil then
		if tick() - shootCurrentTime >= shootCooldown then
			shootCurrentTime = tick()
			Shoot(nearestTarget)
		end
	end
end)

Projectile handler: (client)

local Debris = game:GetService("Debris")

local part = script.Parent

local isHit = false

local despawnTime = 4

local function Damage(hit)
	local character = hit:FindFirstAncestorWhichIsA("Model")
	
	if character then
		script.DamageTarget:FireServer(hit)
		part:Destroy()
	end
end

part.Touched:Connect(function(hit)
	if hit:IsDescendantOf(ZombiesFolder) and not isHit then
		isHit = true
		Damage(hit)
	end
end)

Debris:AddItem(part, despawnTime)

Server Handler: (server)

local damage = 10

local function Damage(hit)
	local character = hit:FindFirstAncestorWhichIsA("Model")

	if character then
		local humanoid = character:FindFirstChildOfClass("Humanoid")

		if humanoid then
			humanoid:TakeDamage(damage)
		end
	end
end

script.Parent.DamageTarget.OnServerEvent:Connect(function(player, hit)
	
	print(hit) -- nothing
	
	if hit then
		Damage(hit)
	end
end)
1 Like

You need to put the remoteevent inside ReplicatedStorage

1 Like

I just tried that but it didn’t work.

1 Like

Did you get any errors? Did you change your variables to game.ReplicatedStorage.DamageTarget?

1 Like

What I meant was this:

image

Could you show the whole thing instead of just these object (like the parents).

1 Like

I got no errors and I did try to use those variables.

1 Like

image

1 Like

There could be something wrong with your actual code. Add a print statement right after you fire the RemoteEvent and let me know if it prints.

I just tried something and it was because I enabled the client script on the client.

1 Like

Ah, since it’s a bullet I’d have to assume that it’s in the server’s control.

Try putting that LocalScript into a place the client can access (like StarterPlayerScripts).

But keep the Script in the bullet

1 Like

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