Cloning enemy from rep storage makes it invincible and unable to take damage

  1. I want to copy an enemy from the server onto the client without it breaking.

  2. I managed to get him to spawn with damage taken but i cant deal damage to him.

image
Screenshot 2024-12-28 215001

  1. Ive tried using diffrent swords, tried using diffrent clientside services, tried using serverstorage but because roblox is shit “REMOTE EVENTS CANT ACCESS SERVERSTORAGE” so that leaves me with another dead end, i spawned the enemy using an remote event and made him take damage using a script but of course hes fucking IMMORTAL and cant take damage.

heres my code: ServerScript

local spawner = script.Parent
local Remotes = game.ReplicatedStorage
local Pests = game.ReplicatedFirst.Pests

local PestChosen

player = game:GetService("Players").PlayerAdded:Wait()


local function SpawnPestsToClient()

local ToSpawn = math.random(1,20)
if (ToSpawn <=8) then
	PestChosen = Pests.Worm
elseif(ToSpawn <=14 and ToSpawn > 8) then
	PestChosen = Pests.Slime
elseif (ToSpawn <=17 and ToSpawn > 14) then
	PestChosen = Pests.Squirrel
elseif (ToSpawn <=19 and ToSpawn > 17 ) then
	PestChosen = Pests.BlueSlime
elseif (ToSpawn == 20) then
	PestChosen = Pests.Raven
end


local haha = PestChosen
print("Spawning..", haha.Name)

local hahaclone = haha:Clone()

local pest = hahaclone

pest.Parent = game.StarterPack

print(pest)

Remotes.SpawnPests:FireClient(player,pest)

end

while true do 
	wait(20)
	local num

	local num = math.random(1,3)

	for i = 1, num do
		SpawnPestsToClient()
	end
end

Local Script:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Plate = workspace:WaitForChild("Base")
local PlatePos = Plate.Position
local PlateSize = Plate.Size


local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remotes = ReplicatedStorage


local function SpawnPests(pest)
	print("Spawning pest...")

	-- Generate random positions within PlateSize bounds
	local RandomX = math.random(0, PlateSize.X) - PlateSize.X / 2
	local RandomZ = math.random(0, PlateSize.Z) - PlateSize.Z / 2

	-- Clone the pest
	local clone = pest:Clone()
	clone.Parent = game.Workspace

	-- Set the Humanoid health if it exists
	local cloneHumanoid = clone:FindFirstChild("Humanoid")
	if cloneHumanoid then
		cloneHumanoid.Health = 4
	end

	-- Move the clone to a random position on the plate
	clone:MoveTo(Vector3.new(
		PlatePos.X + RandomX,
		PlatePos.Y + 2, -- Adjust Y to avoid collision issues
		PlatePos.Z + RandomZ
		))
end

-- Connect the function to the RemoteEvent
Remotes.SpawnPests.OnClientEvent:Connect(SpawnPests) 

I’m not asking for anybody to rewrite my scripts i just want to figure out a way i can deal damage to the enemy…

heres what it prints

  • The client can’t access ServerStorage but I get what your trying to say.
  • Instead of using ServerStorage use ReplicatedStorage
    (not the same as ReplicatedFirst)

You're main issue is related to doing damage, but none of the code you posted has anything to do with dealing damage, so keep looking until you find the part that does i guess

ive tried that aswell already, and sadly did not work aswell…

spawning is just fine and i wouldnt even need the remote event to spawn on client but its just when i clone the enemy he just doesnt take dmg if i just put an enemy into the server it works fine so im so confused

What do you normally use to deal damage

i just use the default roblox sword and that should work perfectly fine

Evidently its not.

You’re issue issue is that your still calling clone() on the client portion (local script).
This means that after your server script has:

  1. Cloned a model(?) from the ReplicatedFirst service? (Probably not a great idea long term)
  2. Parented that cloned object to the … StarterPack? For some reason?

You’re local script then gets the pest argument, clones it again, and puts it into the workspace.

So not only do you have a fat memory leak thats going to slow your servers down every time a pest spawns, but now you also have the clone that made on the server (that would normally work with the roblox default swords like youre complaining they arent) is just sitting in the StarterPack. Meanwhile, the clone you made on the client, that the server cant see, is what you’re trying to interact with.

so what should i do… then? im sorry dont be mad at me i already feel guilty for asking for help sorry…

Okay so ive removed that line from the script and you know what that causes…?

it causes attempt to index nil with clone: which is caused when roblox remote event cant pass over something from serverstorage onto the client… ;-;

Thanks for at least trying instead of giving into the learned helplesness.

Replace this part in the local script

-- Clone the pest
local clone = pest:Clone()
clone.Parent = game.Workspace

With this:

-- Clone the pest
local clone = pest -- You already made a clone on the server part
clone.Parent = game.Workspace

This should be the bare minimum change needed to make it work

Also future tip: If you’re coming here to ask for help, and you post a bunch of unformatted code (like you did), people are going to ignore you

uhm i tried to format it but it didnt work…

also yes i did that just now haha

did you damage it with a server script that was made on client? if so damage it from client script

as u can see it des spawn the squirrel on the server it just roblox is sh#% and cant transfer serverstorage stuff to clientside…


heres what happends

If you’re spawning the NPC on the client, and dealing damage with the sword you mentioned; it won’t work. If I’m not mistaken the Classic Roblox Sword is server sided, (of course), meaning the server isn’t recognising the NPC being there at all.

i see… what about this health bar? is there an way of updating it? or should i just stop and take the bullet and have everybody be able to attack others pests…

heres the health bar thing:
image

btw no i did not fix it this is just a clientside clone that simply does not work

Pretty sure it doesn’t matter whether it’s server or client for changing the GUI size, as long as the server handles the damaging, the health will be accurate across all clients.


Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
    local Health = humanoid.Health
    local MaxHealth = humanoid.MaxHealth
    HealthBar.Size = UDim2.new(Health / MaxHealth, 0, 1, 0) 
end)

Just post a picture of the scripts code in studio at this point

i have a system like that… sadly it only updates if the enemy is on serverside though haha :slight_smile: