Multiplying WalkSpeed by Decimal results in 0

Friend needed help fixing something, when doing WalkSpeed * 0.3 (where WalkSpeed is 16) it’s product is 0.

Here is the function:

function Limitless(char, hrp, hum, player)
	local mf = {
		originalwalkspeed = 16,
		originaljumppower = 50,
		originaljumpheight = 7.2,
	}

	local players = game:GetService("Players")
	game:GetService('RunService').Heartbeat:Connect(function()
		for i,v in pairs(players:GetPlayers()) do
			if v == player then return end 
			local eroot = v.Character:FindFirstChild("HumanoidRootPart")
			local ehum = v.Character:FindFirstChild("Humanoid")
			local distance = (hrp.Position - eroot.Position).Magnitude
			if distance <= 6 then
				print(wait(3) .. "found ".. tostring(v.Name))
				pcall(function() print(ehum.WalkSpeed * 0.3)end) -- here it prints 0
				ehum.WalkSpeed = ehum.WalkSpeed * distance / 10
				ehum.JumpPower = ehum.JumpPower * distance / 10
				ehum.JumpHeight = ehum.JumpHeight * distance / 10
				for _, anims in pairs(ehum:GetPlayingAnimationTracks()) do
					print(anims)
					anims:AdjustSpeed(0.05)
				end
			else
				ehum.WalkSpeed = mf.originalwalkspeed
				ehum.JumpPower = mf.originaljumppower
				ehum.JumpHeight = mf.originaljumpheight
				for _, anims in pairs(ehum:GetPlayingAnimationTracks()) do
					print(anims)
					anims:AdjustSpeed(1)
				end
			end
			
			
			for _, part in ipairs(v:GetChildren()) do
				if part:IsA('BasePart') or part:IsA('Model') then
					part.Anchored = true
					part.Velocity = Vector3.new(0, 0, 0)
				elseif part:FindFirstChild("Humanoid") then
					print("PART HAS A HUMANOID: WILL NOT ANCHOR")
					break
				end
			end

			for _, part in ipairs(v:GetChildren()) do
				if part:IsA('BodyVelocity') then
					part:Destroy()
				end
			end 

		end
	end)
end
2 Likes

Have you tried checking/printing the original WalkSpeed of ehum before multiplying it? I think it’s because an external script or function is modifying the WalkSpeed to zero. Also, it may be because you are using a pcall to debug the WalkSpeed of ehum.

2 Likes

Seems to me that you’re reducing the walkspeed every heartbeat until it’s 0. Distance/10 will be below 1, so you’re just reducing the walkspeed every heartbeat

2 Likes

remove the heart beat or maybe set the walkspeed somewhere else
or try this script:

function Limitless(char, hrp, hum, player)
	local mf = {
		originalwalkspeed = 16,
		originaljumppower = 50,
		originaljumpheight = 7.2,
	}

	local players = game:GetService("Players")
	for i,v in pairs(players:GetPlayers()) do
		if v == player then return end 
		local eroot = v.Character:FindFirstChild("HumanoidRootPart")
		local ehum = v.Character:FindFirstChild("Humanoid")
		local distance = (hrp.Position - eroot.Position).Magnitude
		if distance <= 6 then
			print(wait(3) .. "found ".. tostring(v.Name))
			pcall(function() print(ehum.WalkSpeed * 0.3)end) -- here it prints 0
			ehum.WalkSpeed = ehum.WalkSpeed * distance / 10
			ehum.JumpPower = ehum.JumpPower * distance / 10
			ehum.JumpHeight = ehum.JumpHeight * distance / 10
			for _, anims in pairs(ehum:GetPlayingAnimationTracks()) do
				print(anims)
				anims:AdjustSpeed(0.05)
			end
		else
			ehum.WalkSpeed = mf.originalwalkspeed
			ehum.JumpPower = mf.originaljumppower
			ehum.JumpHeight = mf.originaljumpheight
			for _, anims in pairs(ehum:GetPlayingAnimationTracks()) do
				print(anims)
				anims:AdjustSpeed(1)
			end
		end
		
		
		for _, part in ipairs(v:GetChildren()) do
			if part:IsA('BasePart') or part:IsA('Model') then
				part.Anchored = true
				part.Velocity = Vector3.new(0, 0, 0)
			elseif part:FindFirstChild("Humanoid") then
				print("PART HAS A HUMANOID: WILL NOT ANCHOR")
				break
			end
		end
	
		for _, part in ipairs(v:GetChildren()) do
			if part:IsA('BodyVelocity') then
				part:Destroy()
			end
		end
	end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.