RemoteServer:FireServer() did i do it wrong?

Hello!

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.

HERE’S a GIF: https://i.gyazo.com/49518bd8490aa4dfc891b8efcacb2d35.mp4
Script:

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)

Support is appreciated!

image

I think you should do it like this:

RemoteEvent:FireServer(Copy,Character)

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.

2 Likes

Where should I put the server script at?

1 Like

You should insert it in ServerScriptService. But it’ll also work in Workspace.

2 Likes

image

it sends an error (30 Characters)

I’d recommend you listen for player.CharacterAdded instead of calling player.Character.

that’s from the script i made, @jrelvas made it into a script

I’ve tested the script I gave you and it seems to be working on my end. Make sure the function of the remote event is only fired by the RemoteEvent.