New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
0

# How would i get the player from the character?

[All I want to know is what would I put in the parameters for the :GetPlayerFromCharacter(), or what could I do to get the player]

Code(it is in a TextButton that is inside a Gui that is inside StarterGui):

function onClicked()
local p = game.Players:GetPlayerFromCharacter()
local t = script.Parent.Parent.Parent.Parent.Character.Torso
if p.TeamColor == "Bright bluish green" then
t.CFrame = game.Workspace.MiningTycoon.Tycoons.Diamond.Essentials.Spawn.CFrame
elseif p.TeamColor == "Really red" then
t.CFrame = game.Workspace.MiningTycoon.Tycoons.Ruby.Essentials.Spawn.CFrame

end
end

script.Parent.MouseButton1Down:connect(onClicked)


1
xuefei123 209
4 years ago

Well, you don't need to use :GetPlayerFromCharacter(), because this is in the player all ready, you could just do:

local player = script.Parent.Parent.Parent.Parent--This would work if the TextButton's parent was a screen GUi in the StarterGui


But to use the GetPlayerFromCharacter, you still need the player, eg

local player = script.Parent.Parent.Parent.Parent
function onClicked()
local p = game.Players:GetPlayerFromCharacter(player.Character)
local t = script.Parent.Parent.Parent.Parent.Character.Torso
if p.TeamColor == "Bright bluish green" then
t.CFrame = game.Workspace.MiningTycoon.Tycoons.Diamond.Essentials.Spawn.CFrame
elseif p.TeamColor == "Really red" then
t.CFrame = game.Workspace.MiningTycoon.Tycoons.Ruby.Essentials.Spawn.CFrame

end
end

script.Parent.MouseButton1Down:connect(onClicked)


If this helps, why don't you click that accept answer button? It gives us both rep!!

0
0
Is this what Scripting Helpers has become? A place that used to have good questions, a place that people only answer questions for reputation instead of for the sake of helping people's games? You can't only like the reputation, which is a title, and not want to do it for the other people. You asking for acceptance twice? LordDragonZord 3358 — 4y
0
Sorry if it seems mean but, It's the truth, gotta do things the hard way. I lost 100+ reputation because of a guy named Jaja. LordDragonZord 3358 — 4y
-1
To use :GetPlayerFromCharacter(), the parameter is for the Character. Now, with a GUI you wouldn't really have a good reason to use it, at least, not with what you're doing. You should always use a localscript for GUI's which to get the player for a LocalScript, all you need to do is local Variable = game.Players.LocalPlayer and now you have the Player.
script.Parent.Touched:connect(function(hit) -- assuming script is in the part