Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Why does this GUI not clone properly?

Asked by
KarlXYZ 120
9 years ago

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)

2 answers

Log in to vote
0
Answered by 9 years ago

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)
0
Thanks for that, I'll have a look now. KarlXYZ 120 — 9y
0
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. KarlXYZ 120 — 9y
0
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 KarlXYZ 120 — 9y
0
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 juzzbyXfalcon 155 — 9y
View all comments (11 more)
0
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 KarlXYZ 120 — 9y
0
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. juzzbyXfalcon 155 — 9y
0
Mhm, adding to the fact that there's already GUIs in each player's PlayerGui that are working just fine... KarlXYZ 120 — 9y
0
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... KarlXYZ 120 — 9y
0
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) juzzbyXfalcon 155 — 9y
0
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? KarlXYZ 120 — 9y
0
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... KarlXYZ 120 — 9y
0
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 juzzbyXfalcon 155 — 9y
0
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... KarlXYZ 120 — 9y
0
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) juzzbyXfalcon 155 — 9y
0
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. :) KarlXYZ 120 — 9y
Ad
Log in to vote
0
Answered by
iaz3 190
9 years ago

I believe the problem may be that PlayerGUI does not exist, try adding a check for it?

0
The PlayerGui does exist when I checked using the tool referenced in the question post. KarlXYZ 120 — 9y
0
But does it exist at the time the GUI is cloned and parented? iaz3 190 — 9y
0
Yes, it does exist. I've checked using the tool. KarlXYZ 120 — 9y

Answer this question