Im trying to make a block spawn at the mouse position when the player clicks, but for that i need to specify where the mouse position is.
Localscript:
local replicatedstorage = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
replicatedstorage.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local mousepos = player:GetMouse().hit.Position
game.ReplicatedStorage.CubeSpawn:FireServer()
end end)
local replicatedstorage = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
replicatedstorage.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local mousepos = player:GetMouse().hit.Position
game.ReplicatedStorage.CubeSpawn:FireServer(mousepos) -- send it through here
end
end)
-- The player who fired the remote event is ALWAYS the first argument on the server (don't pass the player from the client)
script.Parent.OnServerEvent:Connect(function(player, mousepos)
local Newpart = Instance.new("Part")
Newpart.Size = Vector3.new(10, 10 ,10)
Newpart.Position = mousepos -- mousepos is already a Vector3, so just use the variable
Newpart.Parent = workspace -- Parent the part to workspace so it's visible
end)
Also, judging by the fact that you detect the remote with script.Parent, I assume the server script is in ReplicatedStorage, and if thats the case, move it to ServerScriptService
You just put your variables inside of the paramteres,
remote:Fire(var1, var2, var3)
and on the server you use the OnServerEvent event to detect whenever it gets fired. It will also return all the variables you put inside the parameters.