You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? I want to make a security scanner that when you click a person, a frame pops up and it has info such as their account age, their rank in the group, and their tools.
-
What is the issue? It is not working when I click a player.
-
What solutions have you tried so far? YouTube videos.
This is my script.
local tool = script.Parent
local frame = game.StarterGui.ScreenGui.Frame --Object path to the GUI frame containing the age and rank textboxes.
local groupID = 4796549 --ID of your group.
local playerMouse = nil
local clickConnection = nil
-- The player mouse is passed in as a parameter of the Equipped event.
tool.Equipped:Connect(function(mouse)
playerMouse = mouse
clickConnection = playerMouse.Button1Down:Connect(function()
if (playerMouse.Target and playerMouse.Target.Parent) then
local player = game:GetService("Players"):GetPlayerFromCharacter(playerMouse.Target.Parent)
if (player) then
frame.Visible = true
frame.AccAge.Text = player.AccountAge
frame.RoleInGroup.Text = player:GetRoleInGroup(groupID)
end
end
end)
end)
-- Make sure they can't use the tool while it is not selected.
tool.Unequipped:Connect(function()
frame.Visible = true
if (clickConnection) then
clickConnection:Disconnect()
clickConnection = nil
end
playerMouse = nil
end)
Little bit of more info. This is a localscript in the tool. The tool is in StarterPack.
2 Likes
You are changing the frame in StarterGui, which will only affect how it loads when new players spawn in. You want to instead access the frame in game.Players.LocalPlayer.PlayerGui after the character has loaded. This should work:
local frame = game.Players.LocalPlayer.PlayerGui.Frame
Also, you should remove the playerMouse = mouse line and just use the mouse variable directly instead. That line is a bit pointless.
1 Like
What is the mouse variable???
tool.Equipped:Connect(function(mouse)
it’s in function(mouse)
you can just access mouse directly instead of adding playerMouse = mouse.
So just replace that with playerMouse = mouse?
Doesn’t work. Thanks for your help though.
if the player mouse is nil, then player mouse.Target doesn’t exist, so everything after that won’t run. Also try using prints to debug it.
Can you change it for me? That would be very nice.
Try this:
local tool = script.Parent
local frame = game.Players.LocalPlayer.PlayerGui.Frame --Object path to the GUI frame containing the age and rank textboxes.
local groupID = 4796549 --ID of your group.
local clickConnection = nil
-- The player mouse is passed in as a parameter of the Equipped event.
tool.Equipped:Connect(function(mouse)
clickConnection = mouse.Button1Down:Connect(function()
if (mouse.Target and mouse.Target.Parent) then
local player = game:GetService("Players"):GetPlayerFromCharacter(mouse.Target.Parent)
if (player) then
frame.Visible = true
frame.AccAge.Text = player.AccountAge
frame.RoleInGroup.Text = player:GetRoleInGroup(groupID)
end
end
end)
end)
-- Make sure they can't use the tool while it is not selected.
tool.Unequipped:Connect(function()
frame.Visible = true
if (clickConnection) then
clickConnection:Disconnect()
clickConnection = nil
end
end)
I might be missing something if it still isn’t working for you. Don’t worry too much if it still won’t work though, that was just a side point I wanted to make and isn’t related to why your script is crashing.
Try changing line 3 to:
local frame = game.Players.LocalPlayer.PlayerGui.Frame
As I had done in the example. I think this should fix the issue you were talking about in the OP.
You’re gonna have to use RayCasting instead of mouse.Target, since mouse.Target cannot detect players from my experience.
So how do I incorporate RayCasting into the script?
Elaborate? I’ve used Mouse.Target in the past to detect player characters, it just can’t detect the client’s own character.
Can you help me fix my script? It wont detect players.
There are two errors that pop-up. It says frame is not a valid member of playergui and its doing the variable to the local script in the tool and then it says stack end.
This is a Local Script right?
It has to be, you can not change anything in PlayerGui on the server’s side.
Yes. It is a local script in the tool.
This might work.
local tool = script.Parent
local frame = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame --Object path to the GUI frame containing the age and rank textboxes.
local groupID = 4796549 --ID of your group.
local clickConnection = nil
-- The player mouse is passed in as a parameter of the Equipped event.
tool.Equipped:Connect(function(mouse)
clickConnection = mouse.Button1Down:Connect(function()
if (mouse.Target and mouse.Target.Parent) then
local player = game:GetService("Players"):GetPlayerFromCharacter(mouse.Target.Parent)
if (player) then
frame.Visible = true
frame.AccAge.Text = player.AccountAge
frame.RoleInGroup.Text = player:GetRoleInGroup(groupID)
end
end
end)
end)
-- Make sure they can't use the tool while it is not selected.
tool.Unequipped:Connect(function()
frame.Visible = true
if (clickConnection) then
clickConnection:Disconnect()
clickConnection = nil
end
end)
No, it doesn’t work. Thanks though.
I did a bit of sorting out in your script, try this.
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local tool = script.Parent
local Frame = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame --Object path to the GUI frame containing the age and rank textboxes.
local groupID = 4796549 --ID of your group.
tool.Activated:Connect(function()
for _,Target in pairs(game.Players:GetPlayers()) do
if Mouse.Target:IsDescendantOf(Target.Character) then
Frame.Visible = true
Frame.AccAge.Text = Target.AccountAge
Frame.RoleInGroup.Text = Target:GetRolesInGroup(groupID)
end
end
end)
Mouse.Button1Up:Connect(function()
Frame.Visible = false
end)
-- Make sure they can't use the tool while it is not selected.
tool.Unequipped:Connect(function()
Frame.Visible = false
end)
Doesn’t work. I don’t know, maybe I should try raycasting? Also, the same error pops-up. It keeps referring to the frame variable.