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

Character is not a valid member of Model?

Asked by 5 years ago
Edited 5 years ago

Basically, I'm trying to make a FE gui that whenever you type the person's name in the first textbox and the position in the second textbox, it moves the player's name in the first textbox to the position from the second textbox. For some reason, it keeps saying Character is not a valid member of Model in the output. Help?

Both of my scripts (if needed local script):

--SERVER SCRIPT--
local RS = game:GetService("ReplicatedStorage")
local twigger = RS.OwnerRemotes:WaitForChild("PosFrame")

twigger.OnServerEvent:Connect(function(plr, plrname, pos)
    game.Workspace:WaitForChild(plrname).Character.HumanoidRootPart.CFrame = pos.CFrame * CFrame.new(0,3,0) -- The problem/error, sorry if lines 5-6 are messed up, they're in the same line, like this green text thingy! :D
end)
--LOCAL SCRIPT--
local RS = game:GetService("ReplicatedStorage")
local remotea = RS.OwnerRemotes:WaitForChild("PosFrame")

script.Parent.CB.MouseButton1Click:Connect(function()

local yeeter = script.Parent.posBox.Text
local yeet = script.Parent.userBox.Text

remotea:FireServer(yeet, yeeter)
end)

2 answers

Log in to vote
0
Answered by 5 years ago

The reason for this is because the player in the Workspace is their character, not the Player object itself. Their player is located in the Players service, whilst their character model is under the workspace. It is not recommended to look in the Workspace for their character, as it is unreliable, you can name anything the same name as the player and it would reference that object and not the player.

You also don't need remote events at all to teleport a player, as clients have network ownership of their character, so if they teleport, it will replicate.

--LOCAL SCRIPT--
local client = game:GetService("Players").LocalPlayer

script.Parent.CB.Activated:Connect(function()
    -- Teleporting code goes here.
end)
Hopefully this answered your question and if it did don't forget to hit that accept button. If you have any other questions then feel free to leave them in the comments.
Ad
Log in to vote
0
Answered by 5 years ago

its because your defining the player's Character twice on line 6 on the server script

 game.Workspace:WaitForChild(plrname).Character.HumanoidRootPart.CFrame = pos.CFrame * CFrame.new(0,3,0)

to fix this just remove Character, since when you use Character the script mistakes it that your trying to get a child of the chosen model, but theres no Character so it returns nil.

 --SERVER SCRIPT--
local RS = game:GetService("ReplicatedStorage")
local twigger = RS.OwnerRemotes:WaitForChild("PosFrame")

twigger.OnServerEvent:Connect(function(plr, plrname, pos)
    game.Workspace:WaitForChild(plrname).HumanoidRootPart.CFrame = pos.CFrame * CFrame.new(0,3,0)
end)

Answer this question