In the past, i had tried this to fetch me variables with player's name and team:
repeat wait() until game.Players.LocalPlayer repeat wait() until game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") player = game.Players.LocalPlayer Mouse = player:GetMouse() Identifier = game.Players.LocalPlayer.PlayerGui.CyborgGui.CyborgVision.Identifier if player.Mouse.Target:GetPlayerFromCharacter()then Player = player.Mouse.Target PlayerName = Player.Name PlayerTeam = Player.TeamColor --This is not a whole script, but a part of it
And it doesn't do anything, really. The variables won't fetch the things. What is wrong?
(I will post the rest of the script if it helps.)
player.Mouse
isn't a thing. If you're referring to the mouse object you made, just use your Mouse
variable (canonical names are lowercase though)
Arbitrary objects don't have a GetPlayerFromCharacter
method. That's a method of the Players
service.
In addition, the Target
is the Part, not, the model that the part is in. It can also be nil
, so be careful.
Here is one way to put all of that together into a fix:
local target = mouse.Target if target then -- Is hovering over something (not the sky) local character = target -- The *part* hovering over repeat character = character.Parent until character:IsA("Model") or character:IsA("Workspace") -- To work on Hats, Tool, Gear, we have to -- go up an unknown number of levels -- Until the workspace, or a model local targetPlayer = game.Players:GetPlayerFromCharacter(character) if targetPlayer then -- `character` is the Character model of player `targetPlayer` print(targetPlayer.Name) end end
Additional note:
This will only happen once. -- When the script loads.
For the effect to be useful, this obviously needs to be happening repeatedly; simplest way is to use a while true do wait()
loop.