When somebody presses a button in a GUI the remote event fires but it places a wall in front of all the players in the server how do I make it so it only spawns in front of the player that made the remote event fire? This script is a server script.
The script
01 | local RemoteEvent = game.ReplicatedStorage.BuildWall |
02 | local Wall = game.ReplicatedStorage.Wall |
03 | local character = script.Parent |
04 |
05 | RemoteEvent.OnServerEvent:connect( function () |
06 | local ClonedWall = Wall:Clone() |
07 | ClonedWall.CFrame = CFrame.new(character:WaitForChild( "HumanoidRootPart" ).Position + (character:WaitForChild( "HumanoidRootPart" ).CFrame.lookVector * 3 )) |
08 | ClonedWall.Orientation = character.HumanoidRootPart.Orientation |
09 | ClonedWall.Parent = game.Workspace |
10 | end ) |
When a client fires a remote event, the player is automatically passed as an argument, which means that you can easily pick up the fire-er serverside.
1 | RemoteEvent.OnServerEvent:Connect( function (player) |
2 | local ClonedWall = Wall:Clone() |
3 | ClonedWall.CFrame = CFrame.new(player.Character:FindFirstChild( "HumanoidRootPart" ).Position + (player.Character:FindFirstChild( "HumanoidRootPart" ).CFrame.lookVector * 3 )) |
4 | ClonedWall.Orientation = player.Character.HumanoidRootPart.Orientation |
5 | ClonedWall.Parent = workspace |
6 | end ) |
Also it seems like you have the script automatically inserted into every player that joins, which is unnecessary. Just keep it in ServerScriptService