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