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

My textlabel doesnt show the speed?

Asked by 4 years ago
Edited 4 years ago

I am trying to make a gui that shows how much speed you have:

01game.Players.PlayerAdded:Connect(function(player)
02   local stats = Instance.new("Folder",player)
03   stats.Name = "leaderstats"
04 
05   local speed = Instance.new("IntValue", stats)
06   speed.Name = "Speed"
07   speed.Value = 16
08 
09   local Gui = game.StarterGui.ScreenGui.Frame.Frame.TextLabel
10 
11   speed.Changed:Connect(function()
12 
13      Gui.Text = "Speed: "..speed.Value
14   end)
15end

This is my whole leaderstats script and down below is my script for the textlabel. But my gui does not even show the speed. I tried it without the function before, but then it doesnt update ther speed value.

0
This is because you're getting the StarterGui not the PlayerGui, try local Gui = player.PlayerGui.ScreenGui.Frame.Frame.TextLabel mixgingengerina10 223 — 4y
0
Do you want the value to change when the player's walkspeed changes? TheWaildug 55 — 4y

3 answers

Log in to vote
2
Answered by 4 years ago

You are getting the StarterGui instead of PlayerGui. That's the problem and you can't change the text's via the server script.

Just Insert a Local script inside the TextLabel.

1local player = game.Players.LocalPlayer
2 
3while wait() do
4 
5script.Parent.Text = player.leaderstats.Speed.Value
6 
7end

Your server script should be:

01game.Players.PlayerAdded:Connect(function(player)
02 
03    local stats = Instance.new("Folder")
04    stats.Name = "leaderstats"
05    stats.Parent = player
06    local speed = Instance.new("IntValue")
07    speed.Name = "Speed"
08    speed.Value = 16
09    speed.Parent = stats
10 
11end)

Also note that it is in efficient to parent first, always parent last.

0
SilentsReplacment, why would I add the 'speed.Parent = stats' if i may ask? MRDelivio06 10 — 4y
0
And it worked btw thank you MRDelivio06 10 — 4y
0
Because you parent the leaderstats(folder) to the player, and the stats inside the leaderstats. SilentsReplacement 468 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

You should use the GetPropertyChangedSignal event instead of the changed event for just one property change (in this case, the value of the "speed" IntValue).

01game.Players.PlayerAdded:Connect(function(player)
02    local stats = Instance.new("Folder",player)
03    stats.Name = "leaderstats"
04    local speed = Instance.new("IntValue", stats)
05    speed.Name = "Speed"
06    speed.Value = 16
07    local Gui = game.StarterGui.ScreenGui.Frame.Frame.TextLabel
08    speed:GetPropertyChangedSignal('Value'):Connect(function()
09        Gui.Text = "Speed: "..speed.Value
10    end)
11end)
0
It still did not work, but thanks for trying MRDelivio06 10 — 4y
0
Please don't feed false information. It's basically the same thing but using GetPropertyChangedSignal. Also you are changing it via StarterGui which is not what the player sees. SilentsReplacement 468 — 4y
Log in to vote
0
Answered by 4 years ago

You need to include the PlayerGui in your code, as that's what the player sees.

01game.Players.PlayerAdded:Connect(function(player)
02    local stats = Instance.new("Folder",player)
03 
04    stats.Name = "leaderstats"
05 
06    local speed = Instance.new("IntValue", stats)
07 
08    speed.Name = "Speed" speed.Value = 16
09 
10    local Gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").Frame.Frame.TextLabel
11 
12    speed.Changed:Connect(function(newValue) -- Added the newValue parameter
13        Gui.Text = "Speed: "..newValue
14    end)
15end)
0
Do what @SilentResponders said and have both a server script and a local script. ParticularlyPenguin 71 — 4y
0
thanks MRDelivio06 10 — 4y

Answer this question