Script doesn't Work, No prints or anything

I wanted to check the range of the player from the generator, I used magnitude to see if the HumanoidRootPart is > The range of the generator, I was testing it But i came across that the output won’t print anything. Here’s my code.

local Generator = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character:WaitForChild("HumanoidRootPart")
local Distance = (Generator.Position - Character.Positon).Magnitude

while true do
wait()
print(Distance)

end

My output:

Explorer:
image

You need to put it in a server script not a local script. Then it should work.

(Local scripts do not print to the output, but they do in the Developer Console in the client part)

Unfortunately as of a update made a while ago, LocalScripts can’t run in the workspace. You need to put it in either StarterPlayerScripts, the Backpack, the Character, or StarterGui for it to run. This is a bit frustrating to work around, but it is very possible to shift LocalScripts to work from one of the working LocalScript locations.

Another option would be to use a Server Script, if that is a possibility for what you are trying to accomplish. A normal Script can be placed pretty much anywhere, except for local directories.

3 Likes

Client prints still show in the output. It’s just that LocalScripts only run in Character,StarterGui,StarterPack,or StarterPlayer.

Oh wait, yeah I also realized the code is calling for a player so @ExcessEnergy is right.

Cool! seems like roblox got wonky again