StringValue changes when hit by car Script

image

image

image
So I have this script that, when hit by a car, the Player’s race (value) will change into a Soul. But when I run the script it isn’t working. Any help is appreciated

local Car = script.Parent
local Player = game.Players.LocalPlayer

Car.Touched:Connect(function(hit)
	

Player.Race.Value = "Soul"
	
end)
1 Like

That is because you are changing the name of the value, not the value itself. It should be
Player.Race.Value = "Soul"


The value higlighted is still unchanged. Is this normal?

Value.Name is an invalid property - just use Value.

In addition to that, your game would be very easy to exploit, for if it is controlled only by the client, then it would not be hard to simply tamper with the value.

If this solution doesn’t help you, it’s because of FilteringEnabled. For your system to work, you’ll need remotes (RemoteEvents/RemoteFunctions) for your thing to replicate.

All in all, I think it’s smarter to control it from the Server, but it’s your game.

1 Like

You’ll need to change the path to the value in order to include your folder “LocalPlayer”, which the value is stored inside of. So you’ll just simply need to use,

Player.LocalPlayer.Race.Value = "Soul"
1 Like

player.LocalPlayer.Race.Value = “Soul”

You also might be getting confused as what Local Player is. When inside of a client script, the line of code, game.Players.LocalPlayer get’s the user’s in-game player. For example, when I join a game, the line of code will retrieve my player “McRocketNuggets” within the Roblox Server. There is no need to create a folder named “LocalPlayer”.

I noticed that the car part was script.Parent. That means you’re in workspace. I also noticed you used game.Players.LocalPlayer. That means it’s a LocalScript. LocalScripts don’t run in workspace.

Your solution? Make it a script and get the character from the Touched event, which would be hit.Parent if it hit a humanoid. You might want to check if hit.Parent:FindFirstChildWhichIsA("Humanoid") is true to ensure that it hit a humanoid. Once you’ve established it’s a humanoid, you can use game.Players:GetPlayerFromCharacter(hit.Parent) to get the player. And then you can edit the Race StringValue inside of the player. You’re welcome :slight_smile:

If you insist on handling this locally, put the LocalScript somewhere else like StarterCharacterScripts and then reference the car part in workspace from there. Then it would also work fine.

No LocalPlayer is a folder he created inside of the player

No, in his code, he specifically set Player to be game.Players.LocalPlayer. That makes it him getting the local player, not a folder. Since he’s getting the LocalPlayer, that means it must be a LocalScript. And again, LocalScripts don’t run in workspace.

image

LocalPlayer is a folder I made inside a player if this is what you meant

Idk man, but in his picture of explorer its clearly shown a folder, and as far I know local scripts can run in workspace too…

I’m not talking about any folders. I’m talking about your line

local Player = game.Players.LocalPlayer

This isn’t getting a folder; this is getting the LocalPlayer.

Ow I totally missed that sorry…

LocalScripts can’t run in workspace; it’s a common misconception. It’s been a complaint in the Developer community for a while now. People have found hacky ways around it, though.

I would use hit.Parent
Hdhxhxxhchchx

LocalPlayer is getting the player that the script is currently running under. LocalPlayer is a folder in his instance, but game.Players.LocalPlayer gets a player object.

Sorry this video I’m watching is making my brain hurt. So are you suggesting that I should rename the “LocalFolder” folder to something else so it will get the folder, not the actual LocalPlayer?

I suggested that instead of putting this in a LocalScript in workspace, which won’t run, you either put it somewhere else and reference the folder LocalPlayer (why you would name it that, I don’t know. It’s rather confusing) in the player object. It would run in a place like StarterCharacterScripts.

Another way you can do it, as I talked about above, was putting this in a Script (server) in workspace instead. And again, if the Race StringValue is in a folder named LocalPlayer (again, why?? :joy:), you’d need to have something like player.LocalPlayer.Race.Value = "Soul" where player is the actual player object you got from Players:GetPlayerFromCharacter() in the Touched event. I explained the process in my first post above.

I wouldnt use the folder in the first place, but if u want it then name it to sth like Values