So i have a frame that a rank in a group can see, which duplicates a button for one for every player in the game. That part is work well, but the following script, to make the actual button work, does not.
What it is supposed to do is to teleport the player that has the name same as the text value on the button to a partivular position.
local t = Vector3.new(129.099, -134.792, 140.913) -- Teleport To
local plName = script.Parent.Text
local p = game.Players:FindFirstChild(plName)
script.Parent.MouseButton1Click:Connect(function()
for i = 1, #p do
p[i].Character:MoveTo(t)
end
end)
This here is where the script is and where is formatted. The script button is parented to called ‘main’ duplicates the button for each player.
the Character’s just a property of the player, not an object. also, a for loop being used in this context doesn’t make much sense. i like your thinking though.
Instead, you should set the CFrame or Position of the character’s HumanoidRootPart.
local t = Vector3.new(129.099, -134.792, 140.913) -- Teleport To
local plName = script.Parent.Text
local p = game.Players:FindFirstChild(plName)
script.Parent.MouseButton1Click:Connect(function(plr)
plr.Character.HumanoidRootPart.Position = t
end)
local Players = game:GetService("Players")
local function GetPlayerByDisplayName(DisplayName)
for _, Player in ipairs(Players:GetPlayers()) do
if Player.DisplayName == DisplayName then
return Player
end
end
end
local Player = GetPlayerByDisplayName("") --Searched player's display name here.
Here’s a fairly simple script which will locate a player instance via their display name, be warned however, display names aren’t unique (can be shared between players) and as such the results could be ambiguous.