Um, a problem with remote events

Sup guys, during the development of the tower defense game, I came across a strange error when I want to take away the health of the base because a zombie pops up an error heres an error:

local ServerStorage = game:GetService("ServerStorage")
local bindables = ServerStorage:WaitForChild("Bindables")
local Update = bindables:WaitForChild("UpdataBaseHealth")
local GameOver = bindables:WaitForChild("GameOver")


local base = {}

function base.Setup(map, health)
	base.Model = map:WaitForChild("End")
	base.CurrentHealth = health
	base.MaxHealth = health
	
	base.updateHealth()
end

function base.updateHealth(damage)
	if damage then
		base.CurrentHealth -= damage
	end
	
	local gui = game.StarterGui.Base
	local percent = base.CurrentHealth / base.MaxHealth
	
	gui.Back.Health.Size = UDim2.new(percent, 0, 1, 0)
	gui["HP text"].Text = base.CurrentHealth.." / "..base.MaxHealth.." HP"
end


	Update.OnServerEvent:Connect(base.updateHealth)
return base

and

function mob.Move(mob, map)
	local humanoidrp = mob:WaitForChild("HumanoidRootPart")
	local humanoid = mob:WaitForChild("Humanoid")
	local waypoints = map.WayPoints

	for waypoint = 1, #waypoints:GetChildren() do
		humanoid:MoveTo(waypoints[waypoint].Position)
		humanoid.MoveToFinished:Wait()
	end
		
	mob:Destroy()
	
	Update:FireServer(humanoid.Health)
end

Well, I thought that needs to change FireServer to FireAllClients and this ll remove the error, but this was another error, so what ll i do?

Hope u ll help

As the error says, FireServer can only be called from local scripts. Changing it to FireAllClients` would work but you would also have to change this:

To this:
Update.OnClientEvent:Connect(base.updateHealtg) and this will need to be on a client side script.

1 Like

but how if this is a module script?

If the module is required via a client/localscript then use the :FireServer() method. If a module is required via a Serverscript then use :FireClient() or :FireAllClients().

module is required by Server Script but if i use :FireClient() i must use OnClientEvent and theres another error:
image

You need to fire the remote from a local script and not a server script. Same with “OnClientEvent” if you want to recieve the event on the server you do, OnServerEvent.

In summary, it would be fix if you create a local script and connecting your event using OnClientEvent. That should work, I also dont reccomend using the same module to fire events for client and server.

2 Likes

Thank u so much! It really fixed my error

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