This is going to be a long one. I am currently working on a shipping game, and i’ve made my own ship spawning system and boatkit.
Ive added a string value to the ship model, and I want it so when you spawn the ship through the spawner’s GUI, the string value is changed to the name of the player who spawned it. This will be used for SurfaceGUIs on the ship for naming the ships.
Make a local script that fires a remote event to a script in serverscriptservice, that script then clones the ship, positions it wherever you want it (infront of the player using cframe or in a harbor I guess). Then you find the text labels through ancestry of the ship (ship.Cabin.TextLabel.Text for example) and change it to the players name (the player value is automatically passed as the first argument every time you fire a remote event). Lastly you just parent it to workspace and the ship will “spawn”.
Example:
--Local Script--
local button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local spawnRemoteEvent = ReplicatedStorage.spawnShip
local shipName = "Lazaga"
button.Activated:Connect(function()
spawnRemoteEvent:FireServer(shipName)
end)
--Server Script--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shipModels = ReplicatedStorage.shipModels -- A Folder containing the ship models
local spawnRemoteEvent = ReplicatedStorage.spawnShipˇ
spawnRemoteEvent.OnServerEvent:Connect(function(plr, shipName)
local character = plr.Character
local humRootPart = character:WaitForChild("HumanoidRootPart") -- Only if we spawn the ship infront of the player or in relation to the players position
local shipModel = shipModels[shipName]
local shipToSpawn = shipModel:Clone()
shipToSpawn.Cabin.TextLabel.Text = plr.DisplayName
shipToSpawn.PrimaryPart.CFrame = humRootPart.CFrame * CFrame.new(0, 0, -25) -- This spawn the ship 25 studs infront of the player
shipToSpawn.Parent = workspace
end)
This is just a very basic spawning system, it doesn’t check if the player has a ship spawned and has no cooldown so the player could just spawn 100’s of huge ships and crash the server. Writing this on mobile so I might’ve made some mistakes and misspelled things. Hope it answered your question and helped, if you have any other questions please ask.
no, ofcourse not, you would just pass the ship you want to spawn as an argument as such:
--Client Code--
--Ship One--
shipSpawnRemote:FireServer("Lazago")
--Ship Two--
shipSpawnRemote:FireServer("Titanic")
--Server Code--
-- Here we handle ALL ships --
shipSpawnRemote.OnServerEvent:Connect(function(player, shipName)
if game:GetService("ReplicatedStorage").ShipFolder[shipName] then -- We check if the ship exists
local shipToSpawn = game:GetService("ReplicatedStorage").ShipFolder[shipName] -- If it does, we set it as the ship we will clone and spawn
else
warn("ship not found")
return end
end
local shipClone = shipToSpawn:Clone()
-- Here you do your positioning, parenting etc
end)
yep, every time a client fires a remote event, the first argument they pass will be the second argument on the server and the player who fired the remote will be the first like this:
--Firing the remote from the Client
randomRemoteEvent:FireServer("MyArgument")
--Listening for the Remote Event on the Server
randomRemoteEvent.OnServerEvent:Connect(function(player, argument) -- Here the first argument is the player and the second argument will be what the player sent
print(player.Name)
print(argument)
end)
-- Output will print
guest1234 -- printing the players name
MyArgument -- printing the argument
you can literally pass anything you want, you can name the ship through it, you would send anything the player has to decide about the ship for example where they want it spawned, what color they want it etc.