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)
Well, this is odd. I am going to ask you to read this link about debugging (as I am assuming you are currently using Online Roblox to debug which is needless unless you are debugging DataStores.)
After you have read that, I suggest to replace your current code by the code below, and check the output to see if the prints run as expected:
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) print("function startOffenderG commenced") local guiOffenderCl = guiOffender:Clone() guiOffenderCl.Parent = oPlayer:FindFirstChild("PlayerGui") print("The offender gui was placed inside: " .. guiOffenderCl.Parent:GetFullName()) wait() guiOffenderCl.startUpBool.Value = true end function startOfficerG(oPlayer) print("function startOfficedG commenced") local guiOfficerCl = guiOfficer:Clone() guiOfficerCl.Parent = oPlayer:FindFirstChild("PlayerGui") print("The offender gui was placed inside: " .. guiOfficerCl.Parent:GetFullName()) wait() guiOfficerCl.startUpBool.Value = true end function onHit(hit) print("The handlePart was touched!") if inPro.Value == false and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= lPlayer.Name then print("There is currently nothing in progress, a humanoid was found and the player hit is not the player using the tool") 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() print("The consentString was changed!") if guiOffenderClone.consentString.Value == "no" then print("The consentString was set to: no") guiOfficerClone.deniedBool.Value = true offenderPlayer.Character.Torso.Anchored = false inPro.Value = false end end) end end function startUp() wait() print("function StartUp commenced") if script.Parent.Parent:IsA("Backpack") then ownerName.Value = script.Parent.Parent.Parent.Name print("Parent of script is a backpack") else if script.Parent.Parent:IsA("Model") then print("Parent of script is a model") ownerName.Value = script.Parent.Parent.Name end end end print("Script is running") script.Parent.Changed:connect(startUp) handlePart.Touched:connect(onHit)
I believe the problem may be that PlayerGUI does not exist, try adding a check for it?