So, I'm writing a script that will pick a random event (This works) and then depending on the event do something (Im only on the sword event). The first bug I noticed, is that the "Intermission" happens twice, and sometimes in the middle of picking random events will decide to happen again. The second problem is, The code wont give any error but the player will not receive the sword. It prints my name "pokemine1o9" and works fine otherwise. Heres the code
local text = script.Parent.GameStatus.TextLabel
local i = 10
local timer = 10
local match = 0
local events = {"One player gets a sword", "A meteor will fall!", "Someone is getting a little tired..."}
local event = ""
while i == 10 do
if match == 0 then
text.Text = timer .. " Seconds left until match start!"
wait(1)
timer = timer - 1
if timer == 0 then
match = 1
end
end
if match == 1 then
wait(5)
local picker = math.random(3)
event = events[picker]
print(event)
text.Text = event
if picker == 1 then
local players = game.Players:GetPlayers()
local nplrs = #players
local Randomplayer = nil
if nplrs > 0 then
Randomplayer = players[math.random(1, nplrs)]
end
print(Randomplayer)
local chosenone = {Randomplayer}
local gear = game.ServerStorage["ClassicSword"]
for i = 1, #players do
if chosenone[1] == Randomplayer.Name then
gear:clone().Parent = Randomplayer:WaitForChild("Backpack")
end
end
end
end
end
As I posted this I found my first error, I used the same name for two different variables. (I posted the new script)
I rewrote some of the script, and I updated it. No errors are fixed

1 comment
Why did you use a PlayerAdded and CharacterAdded event? Someone would only receive the gear then when another player joins.