I am trying to make police system where a police can click on a criminal's body and a gui appears on both the cop and the criminals screen (2 separate guis already made). I made the click detector (not using an actual click detector) and the 2 print statements in my code work, but I keep getting the error message "expected string, got instance" so Im wondering what I did wrong in my code. Thanks!
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local gui = game.StarterGui.PoliceGUI.search --search is the frame I want to show for cop
local target -- just creating a variable
mouse.Button1Down:Connect(function()
target = mouse.Target.Parent
print(target) -- this prints anything the player clicks on (but the parent)
local humanTarget = target:FindFirstChild("Humanoid") -- checks if target has humanoid
if humanTarget ~= nil then
print("humanoid found") -- this works as well
local playergui = game.Players[target]:FindFirstChild("PlayerGui")
playergui.PoliceGUI.searchPrompt.Visible = true -- this frame shows for criminal
gui.Visible = true -- sets cop frame to visible
end
end)

6 comments
thanks im going to try it out right now
Players.Player2.Backpack.LocalScript:18: attempt to index nil with 'PoliceGUI'
the playergui variable is appearing as nil which means that line isn't working. Idk why tho
Are you sure 'PoliceGUI' is where you are referencing it? Does it actually exist where you say it does in the script?
Attempted to index nil with... means it doesn't exist.
btw when I do PlayerGui.PoliceGUI it says attempted to associate a nil value WITH PoliceGUI which means the PlayerGui folder inside the player is nil (nothing)