I’m trying to move a phone Gui, from a cloned tool, into the owner of that cloned tool’s PlayerGui. I know it would be simpler to just have the Gui in StarterGui, however that seems like bad practice to store a large amount of Gui’s in one place, especially when they are only neccessary in very select scenarios (The phone will only have a singular, non-important use). I have settled on using Tool.Equipped:Connect() to signal when the Gui should be reparented, and through reading, I’ve found that the Tool.Equipped call passes the Player’s Mouse as a parameter. I also know that you are able to grab a player’s specific mouse through the use of Player:GetMouse(). Therefore, it seems reasonable to be able to work backwards and get the player of a specific mouse. How would I go about this, if it’s even achievable?
Current Script:
local PhoneGUI = script.Parent
local Phone = PhoneGUI.Parent
Phone.Equipped:Connect(function(mouse)
print(mouse.Parent) --Returns null
local function phoneToggle()
for i, v in pairs(PhoneGUI:GetChildren()) do
if v.ClassName == "Frame" then
if v.Visible == true then
v.Visible = false
else
v.Visible = true
end
end
end
end
phoneToggle()
Phone.Activated:Connect(phoneToggle())
end)
I’m a little confused. When you get a player’s mouse, you already know who is going to be the player. Can you elaborate on where you want to get the player from?
Ah sorry, the script is located inside the tool, which is stored in Replicated Storage. As is the Gui that I am trying to reparent. So when the tool is cloned, and brought to the player’s backpack (through a different script) they are then able to equipped it, firing this script and Tool.Equipped which passes the parameter of the Player’s mouse. The tool equip script is stored inside the part you interact with to pick up the tool.
I don’t think you can pass the player’s mouse if it’s located in the server script, but if you are trying to get the player from Tool.Equipped, @VonsRevenges has mentioned a method you can do to get the player.