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

Script doesn't work to update a string value?

Asked by 2 years ago
Edited 2 years ago

So I have a string value ("Role") in StarterCharacterScripts that is parented to another string value ("Plr") -- (not sure if this is related to the problem)

The script I'm trying is in StarterPlayerScripts. I want it to change the value of "Role" but it doesn't work and I'm wondering what I'm doing wrong:

while true do
wait (.0001)
if script.Parent.Parent.TeamColor == BrickColor.new("White") then
script.Parent.Parent.Character.Plr.Role.Value = "Medic"
end
end
0
is there an error? NotThatFamouss 605 — 2y
0
nope, no errors in output imimicu 7 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

Try:

local player = game.Players.LocalPlayer

repeat wait() until player.Character

while true do
    wait (.0001)
    if player.TeamColor == BrickColor.new("White") then
        player.Character.Plr.Role.Value = "Medic"
    end
end

Make sure it's a localscript

0
I was about to write an answer, but you beat me! (As a brief explanation, you have to wait for the Character to load in or it will return as nil) NotThatFamouss 605 — 2y
0
This worked, thank you! imimicu 7 — 2y
Ad

Answer this question