I'm trying to get the text from a textbox, and tp all invited players to a private server
But when I try to get the player, and I get this error:
Unable to cast value to object
--Local script in a textbutton script.Parent.MouseButton1Click:Connect(function() local pl = script.Parent.Parent.TextBox1.Text local plr = game.Players:GetPlayerFromCharacter(pl) game.ReplicatedStorage.ownerp4:FireServer(plr) end)
--Script in workspace game.ReplicatedStorage.ownerp4.OnServerEvent:Connect(function(n, plr) print(plr) local TS = game:GetService("TeleportService") code = TS:ReserveServer(2097256710) TS:TeleportToPlaceInstance(2097256710, code,{plr}) end)
I get my name in the console, but I don't get teleported to the server
The GetPlayerFromCharacter()
function requires the actual character model, but if you look at pl - it's a variable referencing the Text inside of TextBox1, so a string.
You could instead use FindFirstChild()
using pl:
`local plr = game.Players:FindFirstChild(pl)
Okay, so I changed it to:
script.Parent.MouseButton1Click:Connect(function() if script.Parent.Parent.Parent.global.Value == 1 then local pl = "SharkOfGod" local plr1 = game.Workspace:FindFirstChild(pl) local plr = game.Players:GetPlayerFromCharacter(plr1) print(plr1) print(plr) game.ReplicatedStorage.ownerp4:FireServer(plr1) end end)
But plr is still an object, and if I use
script.Parent.MouseButton1Click:Connect(function() if script.Parent.Parent.Parent.global.Value == 1 then local pl = "SharkOfGod" local plr1 = game.Players:FindFirstChild(pl) local plr = game.Players:GetPlayerFromCharacter(plr1) print(plr1) print(plr) game.ReplicatedStorage.ownerp4:FireServer(plr1) end end)
"plr" is nil EDIT: So I used plr1 and changed the server script a bit, and it worked!