Alright so, I'm trying to make it so I can spawn stuff from a folder in ReplicatedStorage to Workspace but only if it doesn't find the model I want to spawn in. I am fairly new to this scripting thing so I might have some issues. It would be spawned and despawned through a GUI TextButton. The function i'm using is called SpawnFunction. Script inside the ServerScriptStorage [Typical Script]
ReplicatedStorage = game.ReplicatedStorage workspace = game.Workspace -- This is just extra insurance --Made By MillerrIAm --------------------------- --Start Script --Main Script if player,spawn true then workspace:GetChildren(spawn) then workspace:(spawn):Destroy() else ReplicatedStorage.Stipulation:Clone(spawn).Parent = workspace end
Script inside the GUI Button [Local Script]
--Made By MillerrIAm --------------------------- --Start Script --Main Script function onClick() game.ReplicatedStorage.SpawnFunction:InvokeServer("SpawnMe!") --Ignore the name, that's just what i named the model. end script.Parent.MouseButton1Down:connect(onClick) print("GUIButton Working")
For starters, you don't need to reference the workspace hardly ever in a variable. The global workspace
is the quickest and best way to access the workspace.
Anyway, you want to say "The client wants a map from clicking this button, and the server wants to clone it into the workspace" right?
So first, you'd insert a local script into your text button. Then you'd store the replicated storage and a remote event in some variables.
--Client
--local script inside button local replicatedStorage = game:GetService("ReplicatedStorage") local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent") local button = script.Parent local function onClick() remoteEvent:FireServer() end button.MouseButton1Down:Connect(onClick)
--Server
--server script local replicatedStorage = game:GetService("ReplicatedStorage") local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent") local debounce = false local function addMaps() if not debounce then debounce = true local map = replicatedStorage:WaitForChild("Map"):Clone() --Clone the map (should be a model) map.Parent = workspace --parent to workspace else workspace:FindFirstChild("Map"):Destroy() --say you wanted to delete it if you pressed again debounce = false end end remoteEvent.OnServerEvent:Connect(addMaps)
90% sure this is a troll question but maybe you'll learn something. Have at it.