How does this not run in a local script?

hello guys! i made a script that checks a value and depending on the value the player gets speed buffs.

i made a local script in workspace and a string value also in workspace, the script does not run in a local script but it does in a normal script

here is the local script i used:

debounce = 1
Starterplayer = game.StarterPlayer
race = workspace.Race

if debounce == 1 then
	print("debouncing")
	if race.Value == "Race1" then
		Starterplayer.CharacterWalkSpeed += 6
		Starterplayer.CharacterJumpPower += 4
		print("Race changed to Race1")
		debounce = 0
	end
	if race.Value == "Race2" then
		workspace.Damage.Value += 3
		Starterplayer.CharacterWalkSpeed += 4
		print("Race changed to Race2")
		debounce = 0
	end
	if race.Value == "Race3" then
		workspace.Damage += 2
		Starterplayer.CharacterWalkSpeed += 5
		Starterplayer.CharacterJumpPower += 3
		print("Race changed to Race3")
		debounce = 0
	end
	if race.Value == "Race4" then
		Starterplayer.CharacterWalkSpeed += 7
		workspace.Damage += 2
		print("Race changed to Race4")
		debounce = 0
	end
end

The thing is the code does not run in a local script and also i want to place it in a local script so the entire server does not have to use the same boost/perk/buff. Please help.

1 Like

where are you putting the local script?

Yeah, LocalScripts don’t run under the workspace.

They run under:

  • Anything that starts with Starter (subfolders of StarterPlayer though)
  • ReplicatedFirst

So, you can move it to one of those locations, or you can put the code in a normal Script and set the RunContext to Client, because Client scripts that aren’t LocalScripts run under the workspace.

2 Likes

yeah thats what I was thinking

ok thanks. BTW i did search and it said to try on replicatedfirst but i didn`t believe it

it has an error stating “Race is not a valid part of Workspace”. and i checked several times i am sure its in workspace

the localscript is in .Workspace but as @12345koip posted i placed the local script to .ReplicatedFirst

That means the script is running now, great! Assets can take time time to load on the client, so you need to use :WaitForChild.

local race = workspace:WaitForChild("Race")

isint .FindFirstChild the same thing? because thats what i used

nevermind i fixed it but i will mark @12345koip quote as the answer as it is correct

1 Like

FindFirstChild is different to WaitForChild. If the child isn’t there when FindFirstChild is called, it just returns nil. But, using WaitForChild will wait until the child exists, and also allows you to limit the time it waits for.

that seems to be why it didnt work

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.