Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I am wondering how to make a part I place visible for everyone?

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. This script works, but only the localplayer which toggled it can see that the brick is placed

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)

2 answers

✓ Accepted answer

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.

9 comments

0

YES! Thank you so much!! I have only been learning lua for 4 days now, so I'll read through this script and learn a lot, thank you!!

0

@JesseSong ?

0

@NoteSalad No problem, happy to help.

0

Please upvote my comment if I am correct

0

@JesseSong I still don't understand what you mean.

0

On your :FireServer(hitX) event there was no need to have a parameter like hitX.

0

Then the server script wouldn't be able to identify it. We need to transfer it over so the server knows what it is, if I don't put hitX in the parameter then the Server Script won't know what 'X' is.

0

Therefore it will result in either an error or the script will not work properly.

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!

2 comments

0

YES! This worked too! Wow this forum has an awesome community!!

0

Can you please upvote my response?

This discussion is preserved as it was. New answers, comments, and votes are closed.