Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My textlabel doesnt show the speed?

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.

2 comments

0

This is because you're getting the StarterGui not the PlayerGui, try local Gui = player.PlayerGui.ScreenGui.Frame.Frame.TextLabel

0

Do you want the value to change when the player's walkspeed changes?

3 answers

✓ Accepted answer

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.

3 comments

0

SilentsReplacment, why would I add the 'speed.Parent = stats' if i may ask?

0

And it worked btw thank you

0

Because you parent the leaderstats(folder) to the player, and the stats inside the leaderstats.

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)

2 comments

0

It still did not work, but thanks for trying

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.

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)

2 comments

0

Do what @SilentResponders said and have both a server script and a local script.

0

thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.