Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make this script work online?

function whenClicked()
	local wait = workspace:WaitForChild("Player")
	local playerpos = game.Workspace.Player.Torso.Position
	local leftlightpos = game.Workspace.FlashLight1.Union.Position
	local difference = playerpos - leftlightpos
	local number = 50
	if difference.magnitude < number then
		local xyzb = game.Workspace.FlashLight1.Union.PointLight
		xyzb.Range = 45
	end
end

script.Parent.MouseButton1Down:connect(whenClicked)

Basically, the problem I have here is that this script only works in Roblox Studio because a child called "Player" loads in to the game on test mode. However, online "Player" would be registered as the name of the user playing the game, for example if Shedletsky joined my game, "Player" = "Shedletsky". The real problem is that I do not know how to register every single player within this code, except from one person. This theory is correct, because I changed "Player" to "EmperorTerminus" and then I went online and the script seemed to be working but it will not work for everyone else because their name will not be included within the script. Any ideas?

2 comments

0

Is this script in a GUI button?

0

Yes.

1 answer

✓ Accepted answer
local wait = workspace:WaitForChild("Player")

In studio, your character's name is "Player". But on Roblox, you character's name is "EmperorTerminus". Therefore that line won't work online, because it can't find anyone named "Player". It will just wait forever.


If you're working with GUIs, you should be using a local script. That means we can use the LocalPlayer property to get the Player of the client that the local script is running on.

local plr = game.Players.LocalPlayer

Then from there use the Character property to get its character, and from there its torso.

plr.Character.Torso

Although you should definitely do some checks to make sure the character and the torso exist before you use them.

1 comment

0

That makes much more sense, thank you.

This discussion is preserved as it was. New answers, comments, and votes are closed.