so I made a car spawner GUI, whenever you click it, it moves a car model to your character’s HumanoidRootPart, for the test, I used Default freemodel car from the toolbox.
I’ve written a script, which includes RemoteServer:FireServer() in it, but it don’t seem to be working, did i do it wrong? It only spawns the vehicle to players who’ve clicked it.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEventTest")
local GUIButton = script.Parent
local Vehicle = ReplicatedStorage:FindFirstChild("Car")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character
GUIButton.MouseButton1Click:Connect(function()
RemoteEvent:FireServer()
local Copy = Vehicle:Clone()
Copy.Parent = workspace
Copy:MoveTo(Character.HumanoidRootPart.Position)
end)
and on server script, game.ReplicatedStorage.RemoteEventTest.OnServerEvent:connect(function(Player,Vehicle,Character)
—- something like this. I typed this on phone so yeah.
Vehicle:Clone()
Vehicle.Parent = workspace
Vehicle:MoveTo(Character.HumanoidRootPart.Position)
end
You aren’t listening to the remote firing at all, you would need to do the following.
--LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEventTest")
GUIButton.MouseButton1Click:Connect(function()
RemoteEvent:FireServer()
end
--Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEventTest")
local Vehicle = ReplicatedStorage:FindFirstChild("Car")
local Players = game:GetService("Players")
RemoteEvent.OnServerEvent:Connect(function(player)
local Character = player.Character
local Copy = Vehicle:Clone()
Copy.Parent = workspace
Copy:MoveTo(Character.HumanoidRootPart.Position)
end)
Notice how the code is split in 2 scripts? That’s what remoteevents were made for, communication between client and server, basically, you’re asking the server to do X since the client can’t do it itself.