RemoteEvent is not being Recived on one end causing my script to malfunction

  1. I want to make a rock respawn system when the rock breaks and have it give a remote event which is recived waits the respawn time and puts it back in anouther random location

  2. Once I break the part and it gives out a remote event I can see it did with prints It is no recived on the other side and it has me confused

  3. I was on here before I also tried looking at similar problems from other people to try to implement and I have been trying to debug this myself using prints

Input Side:


local RockHealth = script.Parent.Settings.Health
local RockName = script.Parent.Settings.Name
local Rock = script.Parent


RockHealth = 5
RockName = "Rock"

local Event = game.ReplicatedStorage.Remotes.RockDestory
local DamageEvent = game.ReplicatedStorage.Remotes.RockDamage

local ClickDetector = script.Parent.ClickDetector

ClickDetector.MouseClick:Connect(function(player)
	DamageEvent:FireClient(player)
	RockHealth = RockHealth - 1
	print(RockHealth)
	
	
	if RockHealth <= 0 then
		Rock:Destroy()
		Event:FireClient(player)
		print("eventfired")
	end
end)

Reciving End:

-- Services
local RS = game:GetService("ReplicatedStorage")
local WS = game:GetService("Workspace")

-- Variables
local Rock = RS.Rocks.Rock2
local Event = RS.Remotes.RockDestory
local RespawnTime = 3

local possibleLocations = WS.RockPositions:GetChildren()

-- Function to spawn a rock at a random location
local function spawnRock()
	local RandomRock = RS.Rocks:GetChildren() -- Get all rocks in the Rocks folder
	local ChooseRock = RandomRock[math.random(1, #RandomRock)] -- Select a random rock
	
	print(ChooseRock)
	print("spawning") --Test Prints
	
	local clone = ChooseRock:Clone() -- Clones Our Random Rock
	local randomPos = possibleLocations[math.random(1, #possibleLocations)] -- Places Rock in one of the Locations
	randomPos.IsTaken.Value = true
	

	clone.Position = randomPos.Position
	clone.Parent = WS.Rocks
end

-- Initial Rock Spawn
spawnRock()

-- Rock Respawn on Event Trigger
Event.OnServerEvent:Connect(function()
	print("recived") --test print
	task.wait(RespawnTime)
	spawnRock()
end)

It does not end up printing Recived on serverevent

Feel free to ask for more info and anything helps thank you

2 Likes

Where is the input script located?

1 Like

Its located in the part I want to delete

What service? (workspace I’m assuming?)

It starts in ReplicatedStorage and it gets cloned into workspace into its random position

The issue is this line:

Replace it with this one:

DamageEvent:FireServer(player)

Since you’re firing the event with FireClient, the server never receives anything because it’s expecting a client-to-server signal.

1 Like

Now its giving me this error:

FireServer can only be called from the client

(Im assuming it has to be local???)

Correct, and the logic won’t be affected.

Now my damage isn’t working

local RockHealth = script.Parent.Settings.Health
local RockName = script.Parent.Settings.Name
local Rock = script.Parent


RockHealth = 5
RockName = "Rock"
print(RockHealth)

local Event = game.ReplicatedStorage.Remotes.RockDestory
local DamageEvent = game.ReplicatedStorage.Remotes.RockDamage

local ClickDetector = script.Parent.ClickDetector

ClickDetector.MouseClick:Connect(function(player)
	DamageEvent:FireServer(player) ----Changed from FireClient
	RockHealth = RockHealth - 1
	print(RockHealth)


	if RockHealth <= 0 then
		Rock:Destroy()
		DamageEvent:FireServer(player)
		print("eventfired")
	end
end)

I changed the end of the damage function from fire client to fireserver assuming the same logic

1 Like

This should be Event:FireServer(player) if that’s the logic you’re going for.

1 Like

yes thats what I changed it to

This should be the fixed version

local RockHealth = script.Parent.Settings.Health
local RockName = script.Parent.Settings.Name
local Rock = script.Parent

RockHealth = 5
RockName = “Rock”
print(RockHealth)

local Event = game.ReplicatedStorage.Remotes.RockDestory
local DamageEvent = game.ReplicatedStorage.Remotes.RockDamage

local ClickDetector = script.Parent.ClickDetector

ClickDetector.MouseClick:Connect(function(player)
DamageEvent:FireServer(player) ----Changed from FireClient
RockHealth = RockHealth - 1
print(RockHealth)

if RockHealth <= 0 then
Rock:Destroy()
Event:FireServer(player)
print(“eventfired”)
end
end)

If you call :Destroy on the client, nothing will actually happen on the server

This is referred to as a Data Leak, and will caused drained performance as more and more rocks get mined.

what do you suggest I do instead?

Destroy it on the server instead of on the client

So put it on the server when the event is recived? ok

local RockHealth = script.Parent.Settings.Health.Value
local RockName = script.Parent.Settings.Name
local Rock = script.Parent

RockHealth = 5
RockName = "Rock"
print(RockHealth)

local Event = game.ReplicatedStorage.Remotes.RockDestory
local DamageEvent = game.ReplicatedStorage.Remotes.RockDamage

local ClickDetector = script.Parent.ClickDetector

ClickDetector.MouseClick:Connect(function(player)
	print("CLicked")
	DamageEvent:FireServer(player) ----Changed from FireClient
	RockHealth = RockHealth - 1
	print(RockHealth)

	if RockHealth <= 0 then
		Event:FireServer(player)
		print("EventFired")
	end
end)

This still deosn’t print RockHealth or Clicked none of theseValues or function work anymore

I recommend relocating the script to StarterPlayerScripts, as client scripts don’t run when directly in the workspace.

local RS = game:GetService("ReplicatedStorage")
local WS = game:GetService("Workspace")

local Rocks = RS.Rocks
local Rock = Rocks.Rock2

local RockHealth = Rock.Settings.Health
local RockName = Rock.Settings.Name


RockHealth = 5
RockName = "Rock"
print(RockHealth)

local DestroyEvent = RS.Remotes.RockDestory
local DamageEvent = RS.Remotes.RockDamage

local ClickDetector = Rock.ClickDetector

local function Clicked ()
	print("Clicked")
end

ClickDetector.MouseClick:Connect(function()
	Clicked()
end)

--ClickDetector.MouseClick:Connect(function(player)
--	print("CLicked")
--	DamageEvent:FireServer(player) ----Changed from FireClient
--	RockHealth = RockHealth - 1
--	print(RockHealth)

--	if RockHealth <= 0 then
--		DestroyEvent:FireServer(player)
--		print("EventFired")
--	end
--end)

Its no longer detecting any Mouse Clicks