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

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

Asked by 2 years ago

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

0
Is your script's parent a number value? VitroxVox 884 — 2y
0
No, the script's parent is the fistTool. antonisthegod 12 — 2y

1 answer

Log in to vote
0
Answered by
boredlake 256 Moderation Voter
2 years ago

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)
0
Alright, thank you so much! antonisthegod 12 — 2y
0
Hmm, i tried it out, but still no changes.. I am really confused.. antonisthegod 12 — 2y
Ad

Answer this question