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:

game.Players.PlayerAdded:Connect(function(player)
   local stats = Instance.new("Folder",player)
   stats.Name = "leaderstats"

   local speed = Instance.new("IntValue", stats)
   speed.Name = "Speed"
   speed.Value = 16

   local Gui = game.StarterGui.ScreenGui.Frame.Frame.TextLabel

   speed.Changed:Connect(function()

      Gui.Text = "Speed: "..speed.Value
   end)
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.

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.

local player = game.Players.LocalPlayer

while wait() do 

script.Parent.Text = player.leaderstats.Speed.Value

end

Your server script should be:

game.Players.PlayerAdded:Connect(function(player)

    local stats = Instance.new("Folder")
    stats.Name = "leaderstats"
    stats.Parent = player
    local speed = Instance.new("IntValue")
    speed.Name = "Speed"
    speed.Value = 16
    speed.Parent = stats

end)

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).

game.Players.PlayerAdded:Connect(function(player)
    local stats = Instance.new("Folder",player)
    stats.Name = "leaderstats"
    local speed = Instance.new("IntValue", stats)
    speed.Name = "Speed"
    speed.Value = 16
    local Gui = game.StarterGui.ScreenGui.Frame.Frame.TextLabel
    speed:GetPropertyChangedSignal('Value'):Connect(function()
        Gui.Text = "Speed: "..speed.Value
    end)
end)
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.

game.Players.PlayerAdded:Connect(function(player) 
    local stats = Instance.new("Folder",player) 

    stats.Name = "leaderstats"

    local speed = Instance.new("IntValue", stats)

    speed.Name = "Speed" speed.Value = 16

    local Gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").Frame.Frame.TextLabel

    speed.Changed:Connect(function(newValue) -- Added the newValue parameter
        Gui.Text = "Speed: "..newValue
    end) 
end)
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