Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why isn't my running script working/changing the values?

It's a LocalScript in StarterPlayerScripts. Children are speed, maxSpeed, maxExp, exp, level, running. All are NumberValues except for running which is a BoolValue. It's supposed to start off at WalkSpeed 16 and give you exp while holding R over time. The values aren't changing and the output says Pressed r Running Released r Running when I do just that.

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

local speed = script.speed

local maxSpeed = script.maxSpeed

local maxExp = script.maxExp

local exp = script.exp

local running = script.running

local level = script.level
	
	
	mouse.KeyDown:connect(function(key)
		if key == 'r' then
			print("Pressed "..key)
			player.Character.Humanoid.WalkSpeed = speed -- Start Running
			running.Value = true	
			print("Running")
		end
	end)
	
	
	mouse.KeyUp:connect(function(key)
		if key == 'r' then
			print("Released "..key)
			player.Character.Humanoid.WalkSpeed = 16 -- Stop running
			running.Value = false
			print("Walking")
		elseif key == 'e' and speed.Value ~= maxSpeed.Value then
			speed.Value = speed.Value + 16 -- Increase speed
			print("Speed increased to "..speed.Value)
		elseif key == 'q' and speed > 16 then
			speed.Value = speed.Value - 16 -- Decrease speed
			print("Speed reduced to "..speed)
		end
	end)
	
	
	while running do
		wait(3)
			exp.Value = exp.Value + 15
			print("Exp is now"..exp.Value)
	end
		while true do
			wait()
			if exp.Value == maxExp.Value then
				level.Value = level.Value + 1
				print("Level is now"..level.Value)
				exp.Value = 0
				print("Exp is now"..exp.Value)
				maxExp.Value = maxExp.Value + 105
				print("maxExp is now"..maxExp.Value)
				maxSpeed.Value = maxSpeed.Value + 16
				print("maxSpeed is now"..maxSpeed.Value)
			end
		end

2 comments

0

i think like 39 might be the problem. did you mean to do < (less than) instead of ~= (thought this was only used for nil(?))

0

if it doesn't equal maxSpeed

1 answer

✓ Accepted answer

The problem is that your setting those variables to the starting values of those stats In other words they aren't going to update when the numbers are changed. You need to set the variables to the values themselves. So don't do

--Wrong
local speed = script.Speed.Value
--Right
local speed = script.Speed

Otherwise the variable will just be equal to the number you gave it and not the value itself. The former can have it's uses though like when you're comparing a variable to it's starting value.

2 comments

0

Seems to work except for I can't do speed = speed + 1, exp = exp + 15 and so on. Attempt to compare a number with userdata :\

0

-_- Yes you can. You'd have to do speed.Value since speed is referencing the object.

This discussion is preserved as it was. New answers, comments, and votes are closed.