Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Local script not working in published - cloning model to player's camera?

I have a script that duplicates a model from ServerStorage and sends it to the player's camera. It works in studio, but not in published mode.

game.ReplicatedStorage.rings.rings1.OnServerEvent:Connect(function(plrWhoFiredEvent)
	game.ServerStorage.rings:Clone().Parent = workspace.Camera
	wait(210)
	workspace.Camera.rings:Remove()
	
end)

3 comments

0

ServerStorage is for the server only not the client. Also local scripts do not run in the workspace.

0

this local script is inside ServerScriptService, and I tried running it out of Lighting, it also doesn't work

0

(putting the model in lighting instead of serverstorage, i mean, not the local script - for testing purposes)

1 answer

##Problems

It seems that you have a networking issue. You setup an OnServerEvent event to clone the models into the clients Camera.

This is a problem because you can only access the camera on the client, and OnServerEvent events are for the server. You have a backwards setup you see?


##Solution

What you can do is reverse your setup so that you have the server calling a FireClient function, and the client receiving it using the OnClientEvent event.

Your setup would look like this;

Workspace

Script --> 'FireClient' on RemoteEvent.

ReplicatedStorage

RemoteEvent

StarterPack

LocalScript --> 'OnClientEvent' on RemoteEvent.


#####Note: Remove is deprecated! Use Destroy!

If you have any further questions feel free to ask.

Happy developing!

This discussion is preserved as it was. New answers, comments, and votes are closed.