Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Confusion over server scripting with ReplicatedStorage cloning?

Asked by 5 years ago

I've been learning Roblox this week, and ran into some confusion.

1.) Enemies should spawn from the server on all clients

2.) Enemies should run some code (movement, etc)

3.) ...

4.) Profit

Here's some pseudo-ish code I have:

--Script under ServerScriptService

local storage = game:GetService("ReplicatedStorage")

local enemy = storage:FindFirstChild("Enemy"):Clone()
enemy.Parent = game.Workspace

And just a bit more:

--Script on my 'Enemy'

local humanoid = script.Parent:FindFirstChild("Humanoid")

(...)

humanoid.MoveTo(some location)

(Assume the above all compiles and runs - it's not directly from my project)

What I want (and am not getting) is to have my server script spawn an enemy from ReplicatedStorage when needed for all clients, and for said enemy to run some code. In my case, the enemy spawns but the code does not run. I have FE on, but I was unaware if this had any affect since it's server code, not client.

If you can clear up my confusion and/or suggest a better or more proper way to handle such a task, please let me know at least the basics!

Thanks

2 answers

Log in to vote
0
Answered by 5 years ago

Its hard to hit this problem specifically but to kindof sum it up for you. You want to have either a Remote Event or Remote Function that says an Enemy Was Spawned which, can then be forwarded to create a state that can be used as a conditional to run the code. An example would be Calling a RemoteEvent/Function in a server script broadcasting to spawn an enemy and then in the enemy script checking for the broadcast from the RemoteEvent/Function to run the code you want it to run.

If youre still having trouble DM me and ill help you 1 on 1

0
I was under the impression though that any object created on the server and then placed in the workspace would also be synchronized on clients, isn't this true? I don't need to use any RemoteEvents or Functions because the server is the one requesting to create enemies, I just don't understand why the code on my enemy isn't running on clients (it runs on server), even though they are visible Firedan1176 29 — 5y
0
Yea but the script is being run when the game starts rather than when they spawn so you would use either remote events/ function to initialize a spawn function WeBuiltOurOwnWorld 6 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Figured out the problem, I am using Team Create, and my Enemy script is a linked script, which somehow was broken. Added a new script, cut and pasted my code, and it is now working

Answer this question