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

Script to get a player using non-local script doesn't work?

Asked by
Smunkey 95
8 years ago

I have a starter GUI that requires me to get a character using a non-local script, however I can't figure out how to get the player for the life of me.

I've tried

local name = script.(all the parents up to the player the starter gui is in).Name
local player = game.Players.name

But I really don't know how else to go about it. Maybe something like

function onClicked ()
player = script.Parent.Click
end

but that's obviously written really wrong and most likely doesn't work.

Maybe something with the 'GetPlayerFromCharacter' function or something with 'mouse1buttondown', but I don't really know.

0
And what is wrong with script.Parent? To be honest, you shouldn't even be using server scripts inside of a player GUI, they're local by definition. If you want to get the player then just use script.Parent, there's nothing wrong with it. Nauseating 125 — 8y
0
The problem is the gui clones stuff into the player to change their appearance. Which it does, but only on the client, so other players can't see the changes. Knowing the player GUI is local only does help quite a bit though Smunkey 95 — 8y
0
Yeah, definitely use local script here. Think of it like this: Local script only runs on player's computer, and should be used for all sort of visual effects, while regular scripts run on server, which by definition is completely blind, that is, it has nothing to do with displaying visual things like parts or GUIs. ZarsBranchkin 885 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

If your script is designed to go in StaterGui/PlayerGui:

local Player = script;
repeat Player = Player.Parent until Player.Parent == game.Players
-- Player is now your Player.
Ad

Answer this question