Remote event not firing

I am making a game and i ran into a problem with remote event for some reason it isn’t firing.
Local script

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
	if mouse.Target then
		local part = mouse.Target
		if part.Parent.Parent.Name == "Trees" then
            -- i have made sure that this next line runs when i want it to 
			game.ReplicatedStorage.Remote.DamageObject:FireServer(1, part.Parent.Name)
		end
	end
end)

the local scripts work and i have made sure it does and when i want it to so it is not the problem.

Server script

game.ReplicatedStorage.Remote.DamageObject.OnServerEvent:Connect(function(player, id, name)
	local toolDamage = {1}
	if id == 1 then
		local obj = workspace.World.Resources.Trees:FindFirstChild(name)
		local toolId = player.stats.tool.Value
		obj.Health.Value = obj.Health.Value - toolDamage[toolId]
		if obj.Health.Value <= 0 then
			local pos = 1
			for i = 1, #spawned do
				if spawned[i] == obj.Name then
					pos = i
				end
			end
			table.remove(spawned, pos)
			obj:Destroy()
		end
	end
end)

this code never runs no matter what i’ve tryed. Any help?

[Removed since it was a stupid idea by me]

No, why would you fire the server using ReplicatedStorage as an Instance? Haha

i just use it the way i am using it because it works i just think getting the service is just weird when you can just reference it the way i done it so i don’t see why this is the problem also i had it in a different server script and it worked fine but not after i moved it into the new script and change the code inside the thing

Okay sorry guys I’ve just never done it any other way haha. :sweat_smile:

Is there really no one who knows why?

Add a print in your server script

have tryed that nothing happens no where i put it

Where is the script located? Any errors?

no errors and the script is located in the sever script is in ServerScriptService

Does anything print if you put a print kn the top of the script?

nope and i have tryed in every place in the server script

Is the script disabled? Show your explorer window.

Capture

What about your explorer window?


the scripts highlighted in yellow are the scipts that i am talking about

I’m not sure why it isn’t working, looking at the scripts you provided.

But I see that you have a RemoteFunction in ReplicatedStorage. Are you calling that function in the same server script before connecting the event? It will yield (script won’t run) until it receives a callback from the client.

Otherwise I’m not sure what the issue could be, assuming the scripts work as intended as you say.

the RemoteFunction is used in other scripts

If it is any help here is the full server script code.

local area = workspace.World.Map.Forest.Ground.Area
local minX = area.C1.Position.X
local minZ = area.C2.Position.Z
local maxX = area.C2.Position.X
local maxZ = area.C1.Position.Z
local y = 4.5
local maxSpawn = 5
local spawned = {}

while true do
	if not (#spawned == maxSpawn) then
		local missing = maxSpawn - #spawned
		for i = 1, maxSpawn do
			local addPart = true
			for j = 1, #spawned do
				if spawned[j] == i then
					addPart = false
				end
			end
			if addPart then
				table.insert(spawned, i)
				local part = game.ReplicatedStorage.Resources.Tree:Clone()
				part.Parent = workspace.World.Resources.Trees
				part:SetPrimaryPartCFrame(CFrame.new(math.random(minX, maxX), y, math.random(minZ, maxZ)) * CFrame.Angles(0, 0, math.rad(90)))
				part.Name = i
			end
		end
	end
	wait(10)
end

game.ReplicatedStorage.Remote.DamageObject.OnServerEvent:Connect(function(player, id, name)
	local toolDamage = {1}
	if id == 1 then
		local obj = workspace.World.Resources.Trees:FindFirstChild(name)
		local toolId = player.stats.tool.Value
		obj.Health.Value = obj.Health.Value - toolDamage[toolId]
		if obj.Health.Value <= 0 then
			local pos = 1
			for i = 1, #spawned do
				if spawned[i] == obj.Name then
					pos = i
				end
			end
			table.remove(spawned, pos)
			obj:Destroy()
		end
	end
end)

The while loop is causing it. The script is stuck in the while loop

1 Like