Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
1
Answered by
thebayou 441 Moderation Voter
6 years ago

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

Ad

Answer this question