So I wrote a boat shop script where if you have enough money and dont already own it you can buy and spawn the ship or spawn it if you already own it. The one problem is when one person tries to spawn their boat instead of their only being one multiple spawn depending on how many are in the server. Example if there is 5 people 5 boats will spawn and I have 0 clue why
local rem = game.ReplicatedStorage:WaitForChild("BoatRemote") script.Parent.Triggered:Connect(function(player) rem:FireClient(player, "yes") end)
^to activate the boat GUI
local rem = game.ReplicatedStorage:WaitForChild("BoatRemote") rem.OnClientEvent:Connect(function(val, whatever) if val == "yes" then script.Parent.Visible = true end end)
^getting the event and setting the GUI to visible
local rem = game.ReplicatedStorage:WaitForChild("BoatRemote") local boat_desc = script.Parent.Parent.Parent["Boat Description"] local spawn_button = boat_desc.SpawnButton local player = game.Players.LocalPlayer local exit_button = script.Parent.Parent.Parent.TextButton local already_spawned script.Parent.MouseButton1Click:Connect(function() boat_desc["Boat Name"].Text = "Schooner" if player.Boats_bought.schooner_ship.Value == 0 then boat_desc.SpawnButton.Text = "Buy" elseif player.Boats_bought.schooner_ship.Value == 1 and already_spawned == nil then boat_desc.SpawnButton.Text = "Spawn" else boat_desc.SpawnButton.Text = "Despawn" end boat_desc["Stats Window"].SpeedText.Text = "- Speed = 35" boat_desc["Stats Window"].HealthText.Text = "- Health = 600" boat_desc["Stats Window"].CannonText.Text = "- # Of Cannons = 4" boat_desc.BoatImage.Image = "rbxassetid://10811310900" boat_desc.BoatImage.ImageTransparency = 0 boat_desc.Visible = true end) spawn_button.MouseButton1Click:Connect(function() if spawn_button.Text == "Buy" then if player.stats.Gold.Value >= 500 then player.stats.Gold.Value -= 500 player.Boats_bought.schooner_ship.Value = 1 spawn_button.Text = "Spawn" end else if already_spawned == nil then rem:FireServer("schooner") boat_desc.Visible = false script.Parent.Parent.Parent["Boat Description"].Visible = false script.Parent.Parent.Parent.Visible = false already_spawned = "yes" else rem:FireServer("despawn") already_spawned = nil script.Parent.Parent.Parent["Boat Description"].Visible = false script.Parent.Parent.Parent.Visible = false end end end) exit_button.MouseButton1Click:Connect(function() boat_desc.Visible = false script.Parent.Parent.Parent.Parent.Background.Visible = false end)
^boat buying system/GUI once bought or spawned will communicate with the spawn script and make it so no player can spawn more than one at a time
local rem = game.ReplicatedStorage:WaitForChild("BoatRemote") local schooner rem.OnServerEvent:Connect(function(player, val) if val == "schooner" then schooner = game.ReplicatedStorage.Boats.SchoonerShip:Clone() schooner.Parent = workspace elseif val == "despawn" then schooner:Destroy() end end)
^boat spawn
Is the script that clones the object a local script if you only want to copy it for one person?