I want to copy an enemy from the server onto the client without it breaking.
I managed to get him to spawn with damage taken but i cant deal damage to him.
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…
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
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
You’re issue issue is that your still calling clone() on the client portion (local script).
This means that after your server script has:
Cloned a model(?) from the ReplicatedFirst service? (Probably not a great idea long term)
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.
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:
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)