This here is my script: I was trying to make it so that the part that gets created is visible for everyone on the server, I know it has something to do with remoteFunctions, but I just can't figure out how to do it. So the big part I was wondering of is how to make it so that the player which want's to place the brick, can place it, and the mouse.Hit.Position would transfer over to the server, so that the brick the player clones from the replicated storage over to the workspace would have the same position as the player which placed that brick.
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local part = game.Workspace.Pink
UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.P then local hit = mouse.Hit.Position local hitX = hit.X local hitY = hit.Y local hitZ = hit.Z local part = game.ReplicatedStorage.Part local partC = part:Clone() partC.Parent = game.Workspace partC.Position = Vector3.new(hitX,hitY,hitZ) end
end)
You'll have to use a RemoteEvent for this. So, first Insert a RemoteEvent into ReplicatedStorage.
Local Script:
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local part = game.Workspace.Pink UIS = game:GetService("UserInputService") UIS.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.P then local hit = mouse.Hit.Position local hitX = hit.X local hitY = hit.Y local hitZ = hit.Z local part = game.ReplicatedStorage.Part game.ReplicatedStorage.RemoteEvent:FireServer(hitX, hitY, hitZ, part) end end)
Server Script:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player, X, Y, Z, Part) local PartC = Part:Clone() PartC.Parent = game.Workspace PartC.Position = Vector3.new(X,Y,Z) end)
Let me know if it works or not.
This is a fundamental mechanic in all of roblox studio, called filterenabled. What this does is it does not replicate things that the client does to the server, to prevent hackers from exploiting your game. The way you would get around this is putting a remote event in ReplicatedStorage and use a script in Server Script Service to make the part. The local script code would look like this:
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local part = game.Workspace.Pink UIS = game:GetService("UserInputService") UIS.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.P then game.ReplicatedStorage.RemoteEvent:FireServer(mouse.Hit.Position) end end
When the player presses p, the local script fires the remote event, sending the mouse position. On the server, the script would look like this:
local part = game.ReplicatedStorage.Part game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, mousePosition) local partC = part:Clone() partC.Parent = game.Workspace partC.Position = mousePosition end)
You do not need the extra x, y, and z components of the vector in order to place the brick. So thats basically it. This is a pivotal feature in Roblox for good or for bad, who knows. Make sure to remember this for literally EVERYTHING involving the player input, tools, etc. in Roblox.
Hope this helps!