So I am making a Round System based game and things are not going as I am planning.
There are errors everywhere I debugged almost everything except two things.
This one is important
I have a string value which will be inserted to a random player.If a player has that string value they would recieve a powerful weapon more powerful than others.
So I scripted it and it was working fine but the problem is the String Value is not being removed when the Round is over
Here is the script -
for x,v in pairs(plrs) do
local king = plrs[math.random(1, #plrs)]
local KingTag = Instance.new("StringValue")
KingTag.Parent = king
KingTag.Name = "King"
local KingTools = ServerStorage:WaitForChild("KingsTools"):GetChildren()
if player:FindFirstChild("King") then
local RadWeapon = KingTools[math.random(1, #KingTools)]
local ClonedWeapon = RadWeapon:Clone()
ClonedWeapon.Parent = king.Backpack
end
end
-- a few lines later
if player:FindFirstChild("King") then -- removing the string values.
player.King:Destroy()
end
I don’t see any errors and the output too isn’t showing any errors.
the script is looping through each player, each time it picks a “king”, then adds a king tag to that king, then checks if the “player” has the king tag.
if you remove the for loop and the if statement, it should work.
p.s. if player is Local Player, that can only be called in a local script, but what this script is doing, it should be handled by a server script.
local king = plrs[math.random(1, #plrs)]
local KingTag = Instance.new("StringValue")
KingTag.Parent = king
KingTag.Name = "King"
local KingTools = ServerStorage:WaitForChild("KingsTools"):GetChildren()
local RadWeapon = KingTools[math.random(1, #KingTools)]
local ClonedWeapon = RadWeapon:Clone()
ClonedWeapon.Parent = king.Backpack
if this part is only run once, it will only select one king, and add one king tag.
you could try looping through each player and if they have a king tag, destroy it before selecting a new king.
But make sure the king selection is only run once.
(sorry about the delay, I was gonna add a code block, but forgot how to format it.)
Sorry man but the game chooses two players rather than one player.
If you want to know what is #plrs it is a table where I insert players into the table.
Since “king” is the player who has the tag, why don’t you just get the string value from that king and destroy that tag. Also how did you insert the players into a table?