So I'm trying to make a script that gives people with a tester rank a 2x exp boost in my game. Is there any way I can do this? I tried doing it like it is in the following, but it doesn't work, I tested changing the 10x exp one to a name other than mine, and it just gave me 1x exp.
01 | local testers = { "FoxOwO" , "S_naZY" , "jurassicsonic" , "Knineteen19" } |
02 |
03 | game.Players.PlayerAdded:connect( function (player) |
04 | player.CharacterAdded:connect( function () |
05 | local multi = script:WaitForChild( "XP Multiplier" ) |
06 | local multiplier = multi:Clone() |
07 | if player.Name = = "Knineteen19" then |
08 | multiplier.Value = 10 |
09 | elseif player.Name = = testers [ 1 ] or player.Name = = testers [ 2 ] or player.Name = = testers [ 3 ] then |
10 | multiplier.Value = 2 |
11 | else |
12 | multiplier.Value = 1 |
13 | end |
14 | multiplier.Parent = game.Workspace:WaitForChild(player.Name).Humanoid |
15 | end ) |
16 | end ) |
you can use a generic for loop
which literates over a table. You'd use the value to get the object.
01 | --example |
02 |
03 | local testers = { "FoxOwO" , "S_naZY" , "jurassicsonic" , "Knineteen19" } |
04 |
05 | game.Players.PlayerAdded:Connect( function (player) |
06 | player.CharacterAdded:Connect( function (char) |
07 | for i,v in pairs (testers) do -- v is the value and i is the index |
08 | if v = = player.Name then |
09 | -- do stuff |
10 | break |
11 | end |
12 | end |
13 | end ) |
14 | end ) |
you can also use a numeric for loop
,
01 | local testers = { "FoxOwO" , "S_naZY" , "jurassicsonic" , "Knineteen19" } |
02 |
03 | game.Players.PlayerAdded:Connect( function (player) |
04 | player.CharacterAdded:Connect( function (char) |
05 | for i = 1 ,#testers do |
06 | local index = testers [ i ] |
07 |
08 | if index = = player.Name then |
09 | --do stuff |
10 | break |
11 | end |
12 | end |
13 | end ) |
14 | end ) |
You are using an if statement incorrectly.
01 | local testers = { "FoxOwO" , "S_naZY" , "jurassicsonic" , "Knineteen19" } |
02 | if player.Name = = "Knineteen19" then |
03 | multiplier.Value = 10 |
04 | end |
05 | if player.Name = = testers [ 1 ] or player.Name = = testers [ 2 ] or player.Name = = testers [ 3 ] then |
06 | multiplier.Value = 2 |
07 | else |
08 | multiplier.Value = 1 |
09 | end |
10 | multiplier.Parent = game.Workspace:WaitForChild(player.Name).Humanoid |
You could also use a for loop.