So I'm currently working on a tool that uses GUIs and Touched events to function, I'm stuck right now with a certain part that's left me completely confused.
The GUI that's referred to as "guiOffender" never clones to the Offender's PlayerGui, whereas the other GUI known as "guiOfficer" does clone and works as intended, however, this completely confuses me as both GUIs use the same exact code (except for variables) to be cloned.
I've looked at the Output in-game using F9 on both player's sides and have found no errors relating to these scripts.
I ended up using this tool to even confirm that the GUI was even cloned which it was not when looking at the other player's PlayerGui...
I've spent hours so far trying to work out what's wrong including re-writing variables and checking for spelling errors, yet there are none.
I'd appreciate any help given on this matter as I have no idea currently...
local lPlayer = game.Players.LocalPlayer
local handlePart = script.Parent.Handle
local inPro = script.Parent.inProgress
local ownerName = script.Parent.ownerName
local guiOffender = script.Parent.offenderGui
local guiOfficer = script.Parent.officerGui
function startOffenderG(oPlayer)
local guiOffenderCl = guiOffender:Clone()
guiOffenderCl.Parent = oPlayer:FindFirstChild("PlayerGui")
wait()
guiOffenderCl.startUpBool.Value = true
end
function startOfficerG(oPlayer)
local guiOfficerCl = guiOfficer:Clone()
guiOfficerCl.Parent = oPlayer:FindFirstChild("PlayerGui")
wait()
guiOfficerCl.startUpBool.Value = true
end
function onHit(hit)
if inPro.Value == false and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= lPlayer.Name then
local offenderPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
inPro.Value = true
offenderPlayer.Character.Torso.Anchored = true
startOffenderG(offenderPlayer)
wait()
startOfficerG(lPlayer)
wait()
local guiOfficerClone = lPlayer:FindFirstChild("PlayerGui"):FindFirstChild("officerGui")
local guiOffenderClone = offenderPlayer:FindFirstChild("PlayerGui"):FindFirstChild("offenderGui")
guiOffenderClone.consentString.Changed:connect(function()
if guiOffenderClone.consentString.Value == "no" then
guiOfficerClone.deniedBool.Value = true
offenderPlayer.Character.Torso.Anchored = false
inPro.Value = false
end
end)
end
end
function startUp()
wait()
if script.Parent.Parent:IsA("Backpack") then
ownerName.Value = script.Parent.Parent.Parent.Name
else if script.Parent.Parent:IsA("Model") then
ownerName.Value = script.Parent.Parent.Name
end
end
end
script.Parent.Changed:connect(startUp)
handlePart.Touched:connect(onHit)

15 comments
Thanks for that, I'll have a look now.
Right, I tried it on Online mode since Test -> Start just says on the player sessions that the server has shutdown... And the script failed at line 12 saying that Parent is nil. Also neither GUI popped up at this try.
Forgot to mention that was with the new code. The structure of my tool is like this currently: http://i.imgur.com/RYh0lAC.png and http://i.imgur.com/7WY9JHv.png
The server most likely shut down because you are using a while true do loop without a wait() in it in a different script. Also, the error message means it is setting the Parent of the gui to nil. Apparently it cannot find the player or the playergui. Add print(offenderPlayer) after line 30 and see if it prints nil
Adding in the print where you said causes it to print out the other player's name which is what it's meant to do I guess
Yeah, so it finds the player, however it cannot find the PlayerGui. The reason why is completely unknown to me because the only times it shouldn't find the PlayerGui is when the player has just connected to the game, which isn't very likely in your case.
Mhm, adding to the fact that there's already GUIs in each player's PlayerGui that are working just fine...
I've even tried renaming the GUI that works (officerGui) to offenderGui and renaming the original to something else. It still doesn't work and errors where it did previously...
You could try to leave out the findFirstChild and just refer to the Gui directly by doing oPlayer.PlayerGui (Since you are certain it exists anyway)
Seem to be getting somewhere now considering that it now failed whenever it tried to reach the PlayerGui, saying that it wasn't a valid member of Player... Shouldn't it be the other player's username, not Player?
I'm about to try running the script within a Local Script instead, and of course replacing the lPlayer variable. EDIT: Okay, that didn't change anything...
No, it's a player object. The same way you can name a part anything you'll like, but in the out put it will still say "Not a member of part" Also, perhaps you should try to use a loop to check what is in the player: for _,v in pairs (oPlayer:GetChildren()) print(v.Name) end
Okay I did that, and it printed StarterGear, PlayerGui and Backpack which was expected of course, I really don't know what's causing this...
I only just now realised this. Do you have FilteringEnabled set to true? You can find it in the properties of Workspace. Try to turn it off for a second if it is on.. (FilteringEnabled will not allow you to make changes to anything that is not clientsided, including other clients)
Apologies for the late reply, after doing that which didn't work, I tried disabling LoadStringEnabled which I had enabled before working on this project, for some reason having LoadString disabled made it work, and the whole things is now finished, thanks for your consistency on trying to help me get this to work. :)