What I’m trying to achieve is putting a string-value into a plate after the player has teleported to a plate and that being their plate. I want it the game to know that it’s their plate by using a string-value. How would I go about doing this?
Here’s two functions which may help:
function module.TeleportPlayers(players, PlateSpawns)
for i, player in pairs(players) do
if player.Character then
local character = player.Character
if character:FindFirstChild("HumanoidRootPart") then
local rand = Random.new()
player.Character.HumanoidRootPart.CFrame = PlateSpawns[rand:NextInteger(1,#PlateSpawns)].CFrame + Vector3.new(0,10,0)
end
end
end
end
function module.InsertTag(contestants,tagName)
for i, player in pairs(contestants) do
local Tag = Instance.new("StringValue")
Tag.Name = tagName
Tag.Parent = player
end
end
You could make a slight modification in your module.TeleportPlayers function, like so:
-- After the HumanoidRootPart if statement
local rand = Random.new()
local plate = PlateSpawns[rand:NextInteger(1,#PlateSpawns)]
player.Character.HumanoidRootPart.CFrame = plate.CFrame + Vector3.new(0,10,0)
local tag = plate:FindFirstChild("Owner") -- checks for tag
if (not tag) then -- tag doesn't exist yet
tag = Instance.new("StringValue")
tag.Name = "Owner"
tag.Parent = plate
end
tag.Value = player.Name
function module.TeleportPlayers(players, PlateSpawns)
for i, player in pairs(players) do
if player.Character then
local character = player.Character
if character:FindFirstChild("HumanoidRootPart") then
local rand = Random.new()
local plate = PlateSpawns[rand:NextInteger(1,#PlateSpawns)]
player.Character.HumanoidRootPart.CFrame = plate.CFrame + Vector3.new(0,10,0)
local tag = plate:FindFirstChild("Owner") -- checks for tag
if (not tag) then -- tag doesn't exist yet
tag = Instance.new("StringValue")
tag.Name = player.Name
tag.Parent = plate
end
end
end
end
end
Nono, dont change the name, keep it to ‘Owner’
Do this instead:
function module.TeleportPlayers(players, PlateSpawns)
for i, player in pairs(players) do
if player.Character then
local character = player.Character
if character:FindFirstChild("HumanoidRootPart") then
local rand = Random.new()
local plate = PlateSpawns[rand:NextInteger(1,#PlateSpawns)]
player.Character.HumanoidRootPart.CFrame = plate.CFrame + Vector3.new(0,10,0)
local tag = plate:FindFirstChild("Owner") -- checks for tag
if (not tag) then -- tag doesn't exist yet
tag = Instance.new("StringValue")
tag.Name = "Owner"
tag.Value = plr.Name
tag.Parent = plate
end
end
end
end
end
And like @skillednames said, don’t change the name of the string value when creating it, since the script looks for a StringValue named “Owner” when it wants to change the value to the player name, setting it to the player’s name will cause errors, so you’ll probably want to keep it like this: