Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Text not changing after setting values?

Asked by
OldBo5 30
7 years ago
Edited 7 years ago

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.

01local plr = game.Players.LocalPlayer
02local sp = Instance.new("IntValue")
03sp.Value = 100
04plr.PlayerGui.MainUI.Display.SprintPower.Text = "Sprint Power: " ..sp.Value
05sp.Parent = plr
06while true do
07wait()
08function onKeyPress(inputObject, gameProcessedEvent)
09    if inputObject.KeyCode == Enum.KeyCode.R then
10local character = plr.Character
11if character then
12    local hum = character:WaitForChild"Humanoid"
13    if hum then
14        hum.WalkSpeed = 26
15    end
View all 47 lines...

If anyone knows the error please answer this! :)

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. EnderGamer358 79 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

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.

01local plr = game.Players.LocalPlayer
02local sp = Instance.new("IntValue")
03sp.Value = 100
04plr.PlayerGui.MainUI.Display.SprintPower.Text = "Sprint Power: " ..sp.Value
05sp.Parent = plr
06 
07while true do
08wait()
09function onKeyPress(inputObject, gameProcessedEvent)
10    if inputObject.KeyCode == Enum.KeyCode.R then
11local character = plr.Character
12if character then
13    local hum = character:WaitForChild"Humanoid"
14    if hum then
15        hum.WalkSpeed = 26
View all 51 lines...
0
Thanks! OldBo5 30 — 6y
Ad

Answer this question