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

How do I change the text of a TextLabel using an if statement?

I'm trying to make it so that when a player clicks a certain part, it'll give them an "Immunity Idol" and it would replace the text in TextLabel with their username. The players receive an immunity idol when they click the part but the TextLabel does not change at all. Any idea how to fix this?

Here's what I have:

https://pastebin.com/wNGb8kQa

(I don't know how to paste a script in here)

1 answer

You are changing the textlabel to the GUI in the startergui, I recommend you to make a local script inside the script, disable it and put this source

local client = game.Players.LocalPlayer
client.PlayerGui.Idol.Holder.Text = client.Name

and change the first script source to

local ToolNames = {"Immunity Idol"}
local Storage = game:GetService("ServerStorage")
 
local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")
 
 
ClickDetector.MouseClick:connect(function(Player)
    if Player and Player.Character then
        local Backpack = Player:WaitForChild("Backpack")
        for i = 1, #ToolNames do
            local Tool = Storage:FindFirstChild(ToolNames[i])
            if Tool then
                Tool:clone().Parent = Backpack
                local ClonedLocal = script.LocalScript:Clone()
ClonedLocal.Parent = Player.Backpack
ClonedLocal.Disabled = false
            end
        end
    end
end)

Hope it works!

1 comment

0

Did this work?

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