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

Why is my textlabel's text not changing through LocalScript?

So, i've been trying to change the fistText's text for some time now, but am not so sure what's wrong.

local fistValue = 0
local fistText = game.StarterGui.ScreenGui.Menu.MenuGUI.StatFrame.Strenght.Text
local fistTool = script.Parent
local cooldown = false
fistText = ("Strenght:")..(fistValue)
fistTool.Activated:Connect(function()
	if cooldown == false then
		fistValue = fistValue+1
		print(fistValue)
		fistText =("Strenght:")..(fistValue)
		cooldown = true
		if cooldown == true then
			wait(1.3)
			cooldown = false
		end
	end
end)

It would be nice if someone could help me out, thanks

2 comments

0

Is your script's parent a number value?

0

No, the script's parent is the fistTool.

1 answer

✓ Accepted answer

First of all, make sure your LocalScript is a descendant of either the StarterGui, StarterPlayerScripts, the player's character, or ReplicatedFirst. Make sure of this, or else the LocalScript will simply not function. To my knowledge, it seems that you have parented the script to a Tool in the backpack, and for the code sample I am providing to work, you must move the script into the StarterGui. If that has been done, then:

It's because you can't assign a property value to a variable to change it by script. This is because the variable does not save the actual instance that the property is of, but instead only the value itself. As an example, that's exactly what you did in line 02, which would be the same as setting local fistText = (the text). In order to fix this, you must instead set it like this:

local plr = game.Players.LocalPlayer
local fistValue = 0
local fistText = script.Parent.ScreenGui.Menu.MenuGUI.StatFrame.Strenght
local fistTool = plr.Character.Tool -- replace Tool with the tool name that was script.Parent before
local cooldown = false
fistText.Text = ("Strenght:")..(fistValue)
fistTool.Activated:Connect(function()
    if not cooldown then
        fistValue += 1
        print(fistValue)
        fistText.Text =("Strenght:")..(fistValue)
        cooldown = true
        wait(1.3)
        cooldown = false
    end
end)

2 comments

0

Alright, thank you so much!

0

Hmm, i tried it out, but still no changes.. I am really confused..

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