Inserting Values into a part

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
1 Like

One question, how’d I make it so it says the person who touched it’s name instead?

You’d get the player from character, so whatever the parameter use the :PlayerFromCharacter function.

1 Like

Exactly what @WooleyWool stated, you could get the the character using GetPlayerFromCharacter when touching a part:

Part.Touched:Connect(function(Hit)
    local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
end)

Now you can assign the player’s name to your StringValue like so:

local PlateOwner = Instance.new("StringValue", Part)
PlateOwner.Name = "PlateOwner"

PlateOwner.Value = Player.Name

Hope that helps!

1 Like

I just did this, but thanks.

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
1 Like

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
2 Likes

Already does that

tag.Value = player.Name

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:

tag.Name = "Owner"
1 Like