Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Whats wrong with this randomizer script?

Asked by 9 years ago


local player = game.Players:GetPlayerFromCharacter(part.Parent) local stat = "Cash" local num = 0 local amount = 20 local amount2 = 50 local amount3 = 175 while true do -- Constantly Changing Number to Help randomize wait(1) num = num +1 if num >= 10 then num = 0 end end function onTouched(hit) if num <= 5 and player then -- If nubmer is any number bellow or equal to 0 they get 25 cash player.leaderstats[stat].Value = player.leaderstats[stat].Value + amount end if num == 6 or 7 or 8 or 9 and player then -- If number is 6-9 they get 50 cash player.leaderstats[stat].Value = player.leaderstats[stat].Value + amount2 end if num == 10 and player then -- If number is 10 they get 175 cash! player.leaderstats[stat].Value = player.leaderstats[stat].Value + amount3 end end script.Parent.Touched:connect(onTouched)

I see know error in the output box

I dont understand the problem D:

0
num = 1, and you check if num = 5 or higher. Also add ends for ifs Kyokamii 133 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

The problem i noticed was your while true do event. Whenever you say while true do, it will continue to do that action until the event is broken. Therefore the listener will become temporarily nullified



local stat = "Cash" local num = 0 local amount = 20 local amount2 = 50 local amount3 = 175 while wait(1) do -- Constantly Changing Number to Help randomize num = num +1 if num >= 10 then num = 0 end script.Parent.Touched:connect(function(hit) if hit.Parent.Humanoid then print("Its a player") local player = game.Players:GetPlayerFromCharacter(hit.Parent) if num <= 5 then player.leaderstats[stat].Value = player.leaderstats[stat].Value + amount end if num == 6 and num <= 9 player then -- If number is 6-9 they get 50 cash player.leaderstats[stat].Value = player.leaderstats[stat].Value + amount2 end if num == 10 and player then -- If number is 10 they get 175 cash! player.leaderstats[stat].Value = player.leaderstats[stat].Value + amount3 end end end end
Ad

Answer this question