Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make this script work online?

Asked by 8 years ago
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?

0
Is this script in a GUI button? Sublimus 992 — 8y
0
Yes. EmperorTerminus 55 — 8y

1 answer

Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago
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.

0
That makes much more sense, thank you. EmperorTerminus 55 — 8y
Ad

Answer this question