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
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)