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

Why isn't this script displaying the credits on the screen gui?

I want the Gui to show the Credit Count for the local player. I have the Gui in Starter Gui with this script:

local player = game.Players.LocalPlayer
local display = script.Parent.Text
local Credits = player.StatStorage.Credits
	display = "You Have "..Credits.Value.." Credits Left."
	print("Displayed "..player.UserId.."'s Credit Balance of "..Credits.Value)
	
	Credits.Changed:connect(function()
		print("Value Changed")
		display = "You Have "..Credits.Value.." Credits Left."
		print("Displayed "..player.UserId.."'s Credit Balance of "..Credits.Value)
	end)

I first tried changing it from the datastore script but without success so I took it out (making the one above).

Here is the DataStore for it:

local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("TrustCurrency")
local time = require(game.Workspace.getTime)


game.Players.PlayerAdded:connect(function(player)
	local leader = Instance.new("Folder",player)
	leader.Name = "StatStorage"
	local Credits = Instance.new("IntValue",leader)
	Credits.Name = "Credits"
	Credits.Value = ds1:GetAsync(player.UserId) or 0
	ds1:SetAsync(player.Id,Credits.Value)
	print("Initial Load Complete")
	Credits.Changed:connect(function()
		print("Saving Data")
		ds1:SetAsync(player.Id,Credits.Value)
		print("Saved "..player.UserId.."'s Credit Balance of "..Credits.Value)
	end)
end)

game.Players.PlayerRemoving:connect(function(player)
	ds1:SetAsync(player.Id,player.StatStorage.Credits.Value)
	print("Saved "..player.UserId.."'s Credit Balance of "..player.StatStorage.Credits.Value)
end)

1 comment

0

is it printing anything?

1 answer

✓ Accepted answer
local player = game.Players.LocalPlayer
local display = script.Parent
local Credits = player.StatStorage.Credits
    display.Text = "You Have "..Credits.Value.." Credits Left."
    print("Displayed "..player.UserId.."'s Credit Balance of "..Credits.Value)

    Credits.Changed:connect(function()
        print("Value Changed")
        display.Text = "You Have "..Credits.Value.." Credits Left."
        print("Displayed "..player.UserId.."'s Credit Balance of "..Credits.Value)
    end)

it's picky about where .text is from line 2, you had script.Parent.Text

it need to go to line 4 "display.Text = "You have...."

2 comments

0

I figured this out...I had two lines repeated..Thanks!

0

no problem. i tried that before too. i dont know why it's so picky xD

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