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

How do I make the wall spawn at the player who fired the remote event?

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

local RemoteEvent = game.ReplicatedStorage.BuildWall
local Wall = game.ReplicatedStorage.Wall
local character = script.Parent

RemoteEvent.OnServerEvent:connect(function()
	local ClonedWall = Wall:Clone()
	ClonedWall.CFrame = CFrame.new(character:WaitForChild("HumanoidRootPart").Position + (character:WaitForChild("HumanoidRootPart").CFrame.lookVector * 3))
	ClonedWall.Orientation = character.HumanoidRootPart.Orientation
	ClonedWall.Parent = game.Workspace
end)

1 answer

✓ Accepted answer

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.

RemoteEvent.OnServerEvent:Connect(function(player)
    local ClonedWall = Wall:Clone()
    ClonedWall.CFrame = CFrame.new(player.Character:FindFirstChild("HumanoidRootPart").Position + (player.Character:FindFirstChild("HumanoidRootPart").CFrame.lookVector * 3))
    ClonedWall.Orientation = player.Character.HumanoidRootPart.Orientation
    ClonedWall.Parent = workspace
end)

Also it seems like you have the script automatically inserted into every player that joins, which is unnecessary. Just keep it in ServerScriptService

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