I am trying to make a gui that shows how much speed you have:
01 | game.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 ) |
15 | end |
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.
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.
1 | local player = game.Players.LocalPlayer |
2 |
3 | while wait() do |
4 |
5 | script.Parent.Text = player.leaderstats.Speed.Value |
6 |
7 | end |
Your server script should be:
01 | game.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 |
11 | end ) |
Also note that it is in efficient to parent first, always parent last.
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).
01 | game.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 ) |
11 | end ) |
You need to include the PlayerGui in your code, as that's what the player sees.
01 | game.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 ) |
15 | end ) |