Appearance doesn't change when StringValue is changed

https://i.gyazo.com/b72d2b5dcb0b9f3072fc100c95a4ffc5.mp4
So basically, when the player gets hit by a car, the player’s race (string value) changes to “Soul” which is indicated by the value on the bottom right.

image

Now I’m making a script that states if a player’s race is a Soul, then their Torso’s transparency turns 0.5 transparency. The script doesn’t seem to work and I need help. Thanks

local player = game.Players.LocalPlayer

if player.PlayerValues.Race ==  "Soul" then
	
	Parent:FindFirstChild("Humanoid"
	UpperTorso.Transparency = 0.5
	
end

looks like you’re new to scripting. your script has error, so I want to fix them.
where your scripts containing at? is that LocalScript or Script?

If your script type was “Script”, you can’t declare player as “game.Players.LocalPlayer”

It’s a script. So I have to make this script a localscript?

And its contained in the ServerScriptService

You need to check the value of the variable Race with the ‘Value’ property

Your conditional statement needs to look like this.

if player.PlayerValues.Race.Value ==  "Soul" then

Yes.
If you are trying to use a server for client, it won’t work exactly how you want it to since it’s the sever.
Client is the actual player.
If you do it reverse which is server for client and client for server, the client would fail because it’s not designed to be for the server.

Ok I made the script into a localscript and I changed the conditional statement and still it doesn’t seem to function.
image

image

There are error lines where it says “Parent” and “UpperTorso”. I don’t know if this is important but the script still wouldn’t work as intended

If that one was script, you can’t declare player as “game.Players.LocalPlayer” as I was saying.
so what you have to do is:

game.Players.PlayerAdded:Connect(function(Player) -- Fire this script when player added
     repeat wait() until Player:FindFirstChild("PlayerValues") -- Wait and repeat until PlayerValues found.
     local Datas = Player:FindFirstChild("PlayerValues") -- Double check
     if Datas then
          if Datas:FindFirstChild("Race") then -- Check "Race"
               Data.Race.Changed:Connect(function(NewValue) -- Fire when Data is changed
                    if NewValue == "Soul" and Player.Character then -- If NewValue was "Soul" and Character found
                         Player.Character.UpperTorso.Transparency = 0.5 -- Make your action
                    elseif Player.Character then -- If others, changing back? at least your must check that player has character
                          Player.Character.UpperTorso.Transparency = 0
                    end
               end
          end
     end
end)

-- Error fixed by MrMauio
1 Like
local player = game.Players.LocalPlayer

if player.PlayerValues.Race.Value == 'Soul' then
    local char = player.Character
    char:FindFirstChild("Humanoid")
    char.UpperTorso.Transparency = 0.5
end

This should fix your code.

Mitu got the closest to what I was going to type out. Use his code, I’m not quite sure what everyone is trying to achieve.

Wait, hold on, you missed an end

game.Players.PlayerAdded:Connect(function(Player) -- Fire this script when player added
	repeat wait() until Player:FindFirstChild("PlayerValues") -- Wait and repeat until PlayerValues found.
	local Datas = Player:FindFirstChild("PlayerValues") -- Double check
	if Datas then
		if Datas:FindFirstChild("Race") then -- Check "Race"
			Data.Race.Changed:Connect(function(NewValue) -- Fire when Data is changed
				if NewValue == "Soul" and Player.Character then -- If NewValue was "Soul" and Character found
					Player.Character.UpperTorso.Transparency = 0.5 -- Make your action
				elseif Player.Character then -- If others, changing back? at least your must check that player has character
					Player.Character.UpperTorso.Transparency = 0
				end)
			end
		end
	end
end)
1 Like

I tried that script but it still wouldn’t work. One of the ends has an error line on it, could that be why it isn’t working?

It looks like you are very new to this so let me explain.

Lua cannot find any variable named ‘Parent’ or any variable named ‘UpperTorso’.
You need to use your ‘player’ variable that references the local Player object so that you can find the player’s upper torso like this:

player:FindFirstChild("UpperTorso").Transparency = 0.5

You could also make it more readable by creating variables to those objects then access those properties directly like so:

local upperTorso = player:FindFirstChild("UpperTorso")
upperTorso.Transparency = 0.5

I highly recommend that you learn the basics of the Lua language first.

Which one? 30 chars sdhmvnxcnvmbcvb


The first one

Damnit, here’s the fixed version

game.Players.PlayerAdded:Connect(function(Player) -- Fire this script when player added
	repeat wait() until Player:FindFirstChild("PlayerValues") -- Wait and repeat until PlayerValues found.
	local Datas = Player:FindFirstChild("PlayerValues") -- Double check
	if Datas then
		if Datas:FindFirstChild("Race") then -- Check "Race"
			Data.Race.Changed:Connect(function(NewValue) -- Fire when Data is changed
				if NewValue == "Soul" and Player.Character then -- If NewValue was "Soul" and Character found
					Player.Character.UpperTorso.Transparency = 0.5 -- Make your action
				elseif Player.Character then -- If others, changing back? at least your must check that player has character
					Player.Character.UpperTorso.Transparency = 0
				end
			end)
		end
	end
end)

as @MrMauio said, delete ) with red underscore. :slight_smile:

Still isn’t working, I think my roblox studio is cursed or something now

Actually, I just moved it down a line. I put it in the wrong place

1 Like

Did output dropped out an error?

One thing I saw was that the “Data” variable on line 6 to not be the same as the “Datas” variable previously stated in the beginning so I changed it to “Datas” and still no result. (I dont know if its supposed to be like that I just tried)

And there was no error in the output nothing was said