✓ Accepted answer
Hey there!
Lets look at both of your problems.
GuiButton that creates part visible to Server and Client
This one is easier than you might think. All you have to do, is create the part server-side, and it will automatically replicate to the clients.
To accomplish this, set up a RemoteEvent that fires to the server once you click the GuiButton.
Client
local repstore = game:GetService("ReplicatedStorage")
local CreatePart = repstore:WaitForChild("CreatePart")
local gui = script.Parent
gui.MouseButton1Click:Connect(function()
CreatePart:FireServer()
end)
Server
local repstore = game:GetService("ReplicatedStorage")
local CreatePart = repstore:WaitForChild("CreatePart")
CreatePart.OnServerEvent:Connect(function(player)
local char = player.Character
if char then
local p = Instance.new("Part")
p.Size = Vector3.new(1, 1, 1)
p.Color = Color3.new(1, 0, 0)
p.Shape = Enum.PartType.Ball
p.Anchored = true
p.CanCollide = false
p.CFrame = char.HumanoidRootPart.CFrame * CFrame.new(0, 0, -5)
p.Parent = workspace
end
end)
Sending the Mouse through a Remote to the Server
This is not possible. You cannot send the actual mouse object through a remote, because it is strictly client-side.
However, you can send the position where the mouse clicked, and/or the BasePart the mouse clicked on.
Client
local repstore = game:GetService("ReplicatedStorage")
local SendMouseInfo = repstore:WaitForChild("SendMouseInfo")
local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
local target = mouse.Target
local hit = mouse.Hit
if target then
SendMouseInfo:FireServer(target, hit.p)
end
end)
Server
local repstore = game:GetService("ReplicatedStorage")
local SendMouseInfo = repstore:WaitForChild("SendMouseInfo")
SendMouseInfo.OnServerEvent:Connect(function(player, target, position)
print("player: "..player.Name)
print("target: "..tostring(target))
print("position: "..tostring(position))
end)
1 comment
Can you provide code?