I created a script that chooses a number between 1 and 3 and then does something from the number he chooses. The problem is that from what I saw, the script never or almost never chooses the number 1 and also doesn't play the sound I specified for him reproduce regardless of the chosen number. I don't know why this is happening, can someone 9 help me please? script
function eat()
local player = script.Parent.Parent
local power = player.Humanoid
script.Parent.Handle.comendosound:Play()
wait(1.4)
local name = game.Players:WaitForChild(player.Name)
local playerpower = math.random(1,3)
print(playerpower)
if playerpower == 1 then
script.Parent:Destroy()
script.Parent.Handle.sparta:Play()
wait(2.9)
print('11111')
power.WalkSpeed = 30
power.JumpPower = 70
local fire = Instance.new("Fire",player.RightHand)
fire.Color = Color3.fromRGB(106,176,236)
fire.Heat = 5
fire.Size = 3.6
local spek = Instance.new("Sparkles",player.HumanoidRootPart)
local spek2 = Instance.new("Sparkles",player.HumanoidRootPart)
local particle = Instance.new("ParticleEmitter",player.HumanoidRootPart)
particle.Size = NumberSequence.new(2.5)
particle.Color = ColorSequence.new(Color3.fromRGB(0, 0, 0))
particle.Drag = 5
particle.Lifetime = NumberRange.new(0.8)
particle.Rate = 50
particle.Speed = NumberRange.new(10)
local texto1 = name.PlayerGui.appletimemensage.appletimelabel
local texto2 = name.PlayerGui.appletimemensage.time
texto1.BackgroundTransparency = 0
texto2.BackgroundTransparency = 0
texto1.Text = 'the effect was over'
texto2.Text = '10'
repeat
texto2.Text = texto2.Text - '1'
wait(1)
until texto2.Text == '0'
print('repaet')
texto2.Text = ''
texto1.Text = ''
texto1.BackgroundTransparency = 1
texto2.BackgroundTransparency = 1
elseif playerpower == 2 then
script.Parent.Handle.sparta:Play()
print('m9udanca')
script.Parent:Destroy()
elseif playerpower == 3 then
script.Parent.Handle.sparta:Play()
print('1legazingfognf')
script.Parent:Destroy()
end
end
script.Parent.Activated:connect(eat)

3 comments
is it a glitch?
The sound doesn't play because the object holding the sound is deleted. To fix this, make sure "PlayOnRemove" on the sound is checked true. Also, it won't always pick the one you want, you also can't force it to choose one at random.
right,thanks