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

Text in GUI not changing when told to?

Alrighty. So this is what is supposed to happen. When you touch a log, a little GUI pops up on your screen and says "+1 log"

What's happening is the GUI pops up fine, but the text doesn't change to "+1 log." Instead the text is the defualt text (Label).

The script:

script.Parent.Touched:connect(function(hit)
      local character = hit.Parent
      local player = game.Players:GetPlayerFromCharacter(character)
if player ~= nil then

local GUI = Instance.new('ScreenGui', player.PlayerGui)
local GUI.Name = WoodCollected

local TextLabel = Instance.new('TextLabel', GUI)
TextLabel.Size = UDim2.new(0.3, 0, 0.3, 0)
TextLabel.Position = UDim2.new(0.4, 0, 0.3, 0)
TextLabel.Text = "+1 log"
TextLabel.TextScaled = true
TextLabel.BackgroundTransparency = 1

P.S. It's a regular script ( not a LocalScript.)

2 comments

0

It may be that + is part of a string pattern, it shouldn't, but try making it a variable instead, and just call the variable. Any errors when you press F9 and check both Local and Server logs?

0

so make a variable of the text (lets say the variable name is text) and when it says "TextLabel.Text = text?"

1 answer

✓ Accepted answer

I fixed it for ya!

script.Parent.Touched:connect(function(hit)
	
	      local character = hit.Parent
      local player = game.Players:GetPlayerFromCharacter(character)
if player ~= nil then
	
	local GUI = Instance.new('ScreenGui', player.PlayerGui)
GUI.Name = "WoodCollected" 

local TextLabel = Instance.new('TextLabel', GUI)
TextLabel.Size = UDim2.new(0.3, 0, 0.3, 0)
TextLabel.Position = UDim2.new(0.4, 0, 0.3, 0)
TextLabel.Text = "+1 log"
TextLabel.TextScaled = true
TextLabel.BackgroundTransparency = 1

end	 --ends for the if statement
end) --ends for the function

Ok so the first problem that I noticed, when you did

local GUI.Name = WoodCollected

wouldn't work because it is already a local and the "." messes it all up because it needs to equal something

You forgot your ends for the function and the if statement, and the text needed to be inside ""

This is inside a script too. Not a local.

Hope this helped you!

2 comments

0

Thanks dude! Props to you man!

0

Glad to help! :)

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