Hello, I’ve been trying at this for a while but it doesn’t seem to work. I have a teleportation code that sends a player to a place, and then when a player joins that player it is supposed to send them to a certain side of a track. But, when I try to get the character from the remote event function param (plr.Character or plr.CharacterAdded:Wait()), when it is called it always returns:
well, i have a specific case that I need the char in the server script
local script:
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local char = player.Character
local playersInGame = TeleportService:GetLocalPlayerTeleportData()
if playersInGame then
if playersInGame[1] == player.Name then
game.ReplicatedStorage.PlayerPlacement:FireServer("Left", char)
elseif playersInGame[2] == player.Name then
game.ReplicatedStorage.PlayerPlacement:FireServer("Right", char)
end
end
server script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.PlayerPlacement.OnServerEvent:Connect(function(plr, side, char)
if side == "Left" then
local HRP = char:WaitForChild("HumanoidRootPart")
HRP.Position = Vector3.new(31.65, 10, 358.571)
elseif side == "Right" then
local HRP = char:WaitForChild("HumanoidRootPart")
HRP.Position = Vector3.new(2.493, 10, 358.571)
end
end)
in my case i have teleport data from a different place that is used to position the player to a certain side of the map. I don’t know what I should do after here cause teh script doesn’t position.
ServerScriptService.PlayerPlacement:7: attempt to index nil with ‘WaitForChild’
ServerScriptService.PlayerPlacement:11: attempt to index nil with ‘WaitForChild’
here is the code:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.PlayerPlacement.OnServerEvent:Connect(function(plr, side)
local char = plr.Character or plr.CharacterAdded:Wait()
if side == "Left" then
local HRP = char:WaitForChild("HumanoidRootPart")
HRP.Position = Vector3.new(31.65, 10, 358.571)
elseif side == "Right" then
local HRP = char:WaitForChild("HumanoidRootPart")
HRP.Position = Vector3.new(2.493, 10, 358.571)
end
end)
You dont have to send the character argument, in fact, thats a terrible idea, just get the player it returns.
Server:
local RemoteEvent = YourRemoteEvent
RemoteEvent.OnServerEvent:Connect(function(Player, WowArg)
local Character = Player.Character
local RootPart = Character:WaitForChild("HumanoidRootPart")
RootPart.CFrame = CFrame.new(0,0,0) -- now you can mess with the character
Player.DoSomethingHere -- you can also mess with the player.
print(Character, WowArg)
end)
Client:
local RemoteEvent = YourRemoteEvent
RemoteEvent:FireServer("Wow")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playersInGame = TeleportService:GetLocalPlayerTeleportData()
if playersInGame then
if playersInGame[1] == player.Name then
game.ReplicatedStorage.PlayerPlacement:FireServer("Left")
elseif playersInGame[2] == player.Name then
game.ReplicatedStorage.PlayerPlacement:FireServer("Right")
end
end