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
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
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
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
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
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)