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

Text not changing after setting values?

Ok, So I self-debugged it and it does change the value, BUT not the text. It is getting a little annoying so I just came here to ask a question about it.

local plr = game.Players.LocalPlayer
local sp = Instance.new("IntValue")
sp.Value = 100
plr.PlayerGui.MainUI.Display.SprintPower.Text = "Sprint Power: " ..sp.Value
sp.Parent = plr
while true do
wait()
function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.R then
local character = plr.Character
if character then
    local hum = character:WaitForChild"Humanoid"
    if hum then
        hum.WalkSpeed = 26
    end
else
print("no character")
end
			sp.Value = 100
			wait(1)
			sp.Value = 50
			wait(10)
			sp.Value = 0
			if sp.Value == 0 then
				plr.Character.Humanoid.WalkSpeed = 16
			end
	end
end
 
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
function onKeyPressEnd(inputObject, gameProcessedEvent)
local character = plr.Character
if character then
    local hum = character:WaitForChild"Humanoid"
    if hum then
        hum.WalkSpeed = 16
    end
else
print("no character")
end
			sp.Value = 50
			wait(1)
			sp.Value = 100
	end
 
game:GetService("UserInputService").InputEnded:connect(onKeyPressEnd)
end

If anyone knows the error please answer this! :)

1 comment

0

First off I'd put the "Sprint Power" .. sp.Value in brackets, I don't know if this will change anything but it usually helps in telling the computer what to change the text to. Second, make sure you use a local script when calling on "Local Player", because it will substitute the player for nil unless it's in a local script.

1 answer

✓ Accepted answer

Try this, this happened to me while making a gui for my place, I'm pretty sure it's because the script gets the sp value when it fires, and doesn't re-check when it changes, the solution was adding an extra function to detect when the value changes and update the text.

local plr = game.Players.LocalPlayer
local sp = Instance.new("IntValue")
sp.Value = 100
plr.PlayerGui.MainUI.Display.SprintPower.Text = "Sprint Power: " ..sp.Value
sp.Parent = plr

while true do
wait()
function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.R then
local character = plr.Character
if character then
    local hum = character:WaitForChild"Humanoid"
    if hum then
        hum.WalkSpeed = 26
    end
else
print("no character")
end
            sp.Value = 100
            wait(1)
            sp.Value = 50
            wait(10)
            sp.Value = 0
            if sp.Value == 0 then
                plr.Character.Humanoid.WalkSpeed = 16
            end
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)
function onKeyPressEnd(inputObject, gameProcessedEvent)
local character = plr.Character
if character then
    local hum = character:WaitForChild"Humanoid"
    if hum then
        hum.WalkSpeed = 16
    end
else
print("no character")
end
            sp.Value = 50
            wait(1)
            sp.Value = 100
    end

game:GetService("UserInputService").InputEnded:connect(onKeyPressEnd)
end
sp.Changed:connect(function(NewValue)
plr.PlayerGui.MainUI.Display.SprintPower.Text = "Sprint Power: " ..sp.Value
end)
 
 

1 comment

0

Thanks!

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