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

Gui text script fails to show 500 minus the number of deaths the player has?

Asked by 3 years ago

Heres the script

game.StarterGui.ScreenGui.TextLabel.Text = "500 - " .. player.leaderstats.Deaths

Im trying to make it so that the text is 500 minus the number of deaths you have. But it's not working, can anyone help?

3 answers

Log in to vote
0
Answered by 3 years ago

Do something around the lines of

game.StarterGui.ScreenGui.TextLabel.Text = 500 -  player.leaderstats.Deaths

and if the script is in the textlable do

 script.Parent.Text = 500 -  player.leaderstats.Deaths
Ad
Log in to vote
0
Answered by 3 years ago

What you’re doing is concatenation- that is to combine a string and a variable. What you’re looking for is subtraction, a mathematical operation that takes the difference of two numbers. Instead of ”500 -“.. player.leaderstats.Death, it should be “”..500-player.leaderstats.Death

Hope I could help!

Log in to vote
0
Answered by 3 years ago

Problem

You have to access a specific player's PlayerGui. You gotta think of StarterGui like a container. When a Player joins the server, it will replicate its contents to the PlayerGui of a Player.

DataModel > Players > [player.Name] > PlayerGui

Note that changing the properties of an instance in the StarterGui does absolutely nothing.

Fixed LocalScript

wait(5)
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local playerGui = player.PlayerGui

local result = 500 - player.leaderstats.Deaths

playerGui.ScreenGui.TextLabel.Text = tostring(result)

Explanation

I added a wait(5) because the LocalScript ran faster than the leaderstats were loaded. (wait(n) before the code is ran should be okay.)

First, I retrieved the Players service. Always use the GetService method even if you can define the service from the DataModel. So if you change the name of the service, there'll be no errors.

Next, got the client and defined the PlayerGui.

After that, created a variable for the result because if I did what you did, it'll probably not even subtract 500 by the Deaths amount.

Finally, I set the text for the TextLabel. You probably don't need to tostring it, but I feel like you have to.

Answer this question