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

TextLabel.Text is not being changed, but passed value is working?

What the actual hell!

So, why the freak is this not working?

-- Script in SSS

if game:GetService("MarketplaceService"):PlayerOwnsAsset(CurrentPlayer, DoubleCoinGP) then 
				local RewardAmountDB = RewardedTime * 2
				--CurrentPlayer.leaderstats.Cash.Value = CurrentPlayer.leaderstats.Cash.Value + RewardAmountDB
				print(CurrentPlayer.Name,' has been rewarded ',RewardAmountDB,' cash')
				CashToReward = CashToReward + RewardAmountDB
			end
			local RewardAmountDB = nil
			if CurrentPlayer.MembershipType == Enum.MembershipType.Premium then
				local RewardAmountDB = RewardedTime * 2
				print(CurrentPlayer.Name,' has been rewarded ',RewardAmountDB,' cash')
				--CurrentPlayer.leaderstats.Cash.Value = CurrentPlayer.leaderstats.Cash.Value + RewardAmountDB
				CashToReward = CashToReward + RewardAmountDB
			end
			CashToReward = CashToReward + RewardedTime
			print('CashToReward = ',CashToReward)
			local XPTeReward = 0
			if game:GetService("MarketplaceService"):PlayerOwnsAsset(CurrentPlayer, TwiceXP) then 
				XPTeReward = RewardedTime / 2
				print(CurrentPlayer.Name,' has been rewarded ',math.round(RewardedTime / 1),' XP ')
			else
				XPTeReward = RewardedTime / 4
				print(CurrentPlayer.Name,' has been rewarded ',math.round(RewardedTime / 2),' XP')
			end

PreloadRewardUI:FireClient(CurrentPlayer,XPTeReward,CashToReward)

--LocalScript in GUI


function PreloadUI(XP,Cash)
    print("Received order to change ",Player.Name,"'s CashText.Text from ",CashText.Text,' to ',Cash) -- (Output) Received order to change  Player1 's CashText.Text from  999  to  23
    print("Received order to change ",Player.Name,"'s XPText.Text from ",XPText.Text,' to ',XP) -- (Output) Received order to change  Player1 's XPText.Text from  999  to  5.75
    script.Parent.Left.Block.Frame.TextLabel.Text = ''..XP..'.' -- IT DOES NOT CHANGE THE TEXT. It just keeps saying 999
    script.Parent.Right.Block.Frame.TextLabel.Text = ''..Cash..'.' -- NOR THESE TEXTS ARE CHANGED. It just keeps saying 999
end

PreloadRewardUI.OnClientEvent:Connect(PreloadUI)

So, anyone have a clue?

Edit:

This does not work too:

local NewCashText = Cash
	local NewXPText = XP
	print("Received order to change ",Player.Name,"'s CashText.Text from ",CashText.Text,' to ',NewCashText)
	print("Received order to change ",Player.Name,"'s XPText.Text from ",XPText.Text,' to ',NewXPText)
	script.Parent.Left.Block.Frame.TextLabel.Text = ''..NewXPText..'.'
	script.Parent.Right.Block.Frame.TextLabel.Text = ''..NewCashText..'.'

6 comments

0

Made them both to 'Local Function', but did not fix it.

0

May I know these XP and Cash are numeric or string?

0

They are both Numbers

0

I've edited the post with some more context btw

0

Try using tostring(XP) and tostring(Cash)

0

What's Tostring? Can't find anything about that on Google nor Yahoo, lol

1 answer

✓ Accepted answer

I might have potentially found the error. While examining about the stuff in comments, I might have found the error. The problem is maybe TextLabel is not accepting number value. So, you have to convert it to string.

Here's what you must do:

function PreloadUI(XP,Cash)

local Xp = tostring(XP) -- Convert XP to string
local cash = tostring(Cash) -- Convert Cash to string

    print("Received order to change ",Player.Name,"'s CashText.Text from ",CashText.Text,' to ',Cash)
    print("Received order to change ",Player.Name,"'s XPText.Text from ",XPText.Text,' to ',XP) 
    script.Parent.Left.Block.Frame.TextLabel.Text = ''..Xp..'.' 
    script.Parent.Right.Block.Frame.TextLabel.Text = ''..cash..'.' 
end

PreloadRewardUI.OnClientEvent:Connect(PreloadUI)

Lemme know if it helps!

1 comment

0

Oh, now I get it. To-String, Tostring. I thought it was Tost-ring, ghehehe.

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