Putting Objects Into ServerStorage After Input

I want to put a few objects into ServerStorage after the player clicks the play button.

I used a code, that I was sure would work, but there were no errors, and it just didn’t do anything.

There are no errors, so I don’t know what to look for.

Here is my very beginner code.

local storage = game.ServerStorage
local player = game.StarterPlayer

local gui = game.StarterGui
local mapFolder = game.Workspace.Map --the folder where all the map objects are in

gui.ScreenPlay.PlayBtn.MouseButton1Click:Connect(function(MouseBtnClick) --playbutton clicked
	print("PlayClicked")
	mapFolder["Misc."].MenuKid.Parent = storage
	mapFolder["Misc."].Ball.Parent = storage
	mapFolder["Misc."].SmokeParticle.Parent = storage
	--putting all the objects i want gone into storage.
end)

I’m not sure what to do, thank you.

2 Likes

I am assuming that this is a LocalScript. That means that all this is processed by the client, which cannot access some server-sided services, such as ServerStorage and ServerScriptService. That is why you cannot move instances inside those services, because the client has no access to them.
If this was a localscript, I would advise you to move your instances to ReplicatedStorage, which is a shared service with the Server, but that players have access to.
If this is a serverscript, I wouldn’t use MouseButton1Click on a server script, so you will probably have to use remoteevents with both a localscript receiving the Mousebutton1click event and firing the remote event and a serverscript to receive that remote event and handle the instances re-parenting.
Hope this helps!

2 Likes

If this is in a local script you cannot set things to ServerStorage due to the fact that the server is protected, the client cannot access it.

If this script is not in a local script, it needs to be as the client is the only one with access to user input.

You should also be implementing better practices while scripting like using game:GetService() instead of referencing a service directly.

Example:

local storage = game:GetService("ServerStorage")

Reference: Roblox Lua Style guide

Also why are you trying to store these objects? Why not clone them when they are needed and then when not needed just get rid of them? Either through :Destroy or DebrisService

Instance | Documentation - Roblox Creator Hub

Debris | Documentation - Roblox Creator Hub

1 Like

I tried using Destroy but it didn’t. Still no errors, and it’s in a local script.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.