Math.randomseed() / math.random() just changing when respawn

So, I’m working on the same project that I talked about some days ago. [ Link: How to detect if a player took damage ].

Okay, I was going well with the project and bla bla blah.

I was working on that again these days, and I found something that’s kinda annoying for a bloody fighting game. Here is the issue [ Blood warning. ]:

robloxapp-20210405-0232444.wmv

Has you can see, the chance doens’t change until you die.

I already tried fixing that, but without sucess…

here is the code:

local BaseballBat = script.Parent


local Animations = BaseballBat.Animations

local BaseballBatIdle = Animations.BaseballBatIdle

local BaseballBatSwing01 = Animations.BaseballBatSwing01

local BaseballBatSwing02 = Animations.BaseballBatSwing02


local BaseballBatSwing = BaseballBat.Handle.BaseballBatSwing

local Hit01 = BaseballBat.Handle.Hit01

local Hit02 = BaseballBat.Handle.Hit02

local Hit03 = BaseballBat.Handle.Hit03

local Hit04 = BaseballBat.Handle.Hit04

local Critical01 = BaseballBat.Handle.Critical01

local Critical02 = BaseballBat.Handle.Critical02

local Critical03 = BaseballBat.Handle.Critical03

local Critical04 = BaseballBat.Handle.Critical04


local Limbs = game:GetService('ReplicatedStorage').Limbs

local HeadLimbs = Limbs.HeadLimbs

local TorsoLimbs = Limbs.TorsoLimbs


local MathRandom = math.randomseed(0, 1)


Debounce = false


local Track01


BaseballBat.Equipped:Connect(function()
	
	
	Track01 = BaseballBat.Parent.Humanoid:LoadAnimation(BaseballBatIdle)
	
	Track01.Looped = true
	
	Track01:Play()
	
	
end)


local Track02

local Track03


BaseballBat.Activated:Connect(function()
	
	
	if Debounce == false then
		
		
		Debounce = true
		
		
		Track02 = BaseballBat.Parent.Humanoid:LoadAnimation(BaseballBatSwing01)
		
		Track02.Looped = false
		
		Track03 = BaseballBat.Parent.Humanoid:LoadAnimation(BaseballBatSwing02)
		
		Track03.Looped = false
		
		
		if MathRandom == 0 then
			
			
			Track02:Play()
			
			Track03:Stop()
			
			
		else
			
			
			Track03:Play()
			
			Track02:Stop()
			
			
		end
		
	
		BaseballBatSwing:Play()
			
			
		BaseballBat.BaseballBat.Touched:Connect(function(Hit)
				
				
			if Hit.Parent:FindFirstChild('Humanoid') then


				if Debounce == true then
					
					
					if MathRandom == 0 then
							
							
						Hit01:Play()
							
							
						Hit.Parent.Humanoid:TakeDamage(22)


						wait(0.921321512312)


						Debounce = false
						
							
					else
							
							
						if Hit:FindFirstChild('BloodParticle01') then


							Critical01:Play()


							Hit.Parent.Humanoid:TakeDamage(25)


							Hit.BloodParticle01.Enabled = true

							Hit:Destroy()


							wait(0.921321512312)


							Debounce = false
							
							
						end
							
							
							Hit:Destroy()
							

							Debounce = false
							
							
						end
						
							
					end
						
						
				end
					
					
			end)
			
			
		wait(0.921321512312)


		Debounce = false
			
			
		end
			
			
	end)
	

BaseballBat.Unequipped:Connect(function()
	
	
	if Track01 then
	
	
		Track01:Stop()
	
		
	end
	
		
end)

The problem is with the math.randomseed().

  • Tsu Washington / SovietFurryBruh.

math.randomseed sets what you give it as the seed for the pseudo-random generator, so if you give it the same seed and test it multiple times, it will give the same sequence, I think you meant to do math.random,

And the other reason it seems to only change when you respawn is because MathRandom is declared outside of any function or event, so it gets executed once, nothing randomizes it after the first time. To fix it, just put MathRandom = math.random(0,1) in parts where you want it to get a random number again, most probably in the part where you activate the tool

1 Like

Thanks, I’ll see if that works or not.

1 Like

Holy crap, thanks. That worked, I litteraly took 1 day trying to fix that.

Anytime! If you have anymore issues don’t be afraid to make another post!

Okay, thanks for the help. [ characters thing. ]

1 Like