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

PlayerGui not indexable from a HopperBin?

Asked by 10 years ago

I finished writing a headache piece of code, only the find out that line 1 didn't work. I have tried to wrap my head around why it won't work, and the only logical explination I came up with is that PlayerGui can't be indexed from a HopperBin (or the Backpack). Here's the problem code, changed a bit from it's previous version.

print (script.Parent.Parent.Parent:FindFirstChild("PlayerGui").Name)

The script's is heirarchy is as so: game.Players.Player1.Backpack.Tool(HopperBin, not a Tool).Script

It's as if PlayerGui doesn't exist...

Here's all of the code, if it helps.

local menu = script.Parent.Parent.Parent.PlayerGui.tahcune
local selected = menu.selected
local plr = script.Parent.Parent.Parent

function onObjectSelected(mouse)
    local t = Instance.new("Part")
    t.Anchored = true
    t.FormFactor = 2
    t.BottomSurface = "Smooth"
    t.TopSurface = "Smooth"
    t.BrickColor = BrickColor.new(Color3.new(0, 0, 0))
    t.Transparency = 0.65
    t.Position = mouse.Hit.p
    t.Size = Vector3.new(selected.Value.info.hoverSize.Value.X, selected.Value.info.hoverSize.Value.Y / 2, selected.Value.info.hoverSize.Value.Z)
    t.Parent = game.Workspace
    repeat updatePos(mouse, t) until fired == true
    onPurchase(t)
    t:Destroy()
end

function updatePos(mouse, object)
    t.Position = Vector3.new(math.ceil(mouse.Hit.X), object.Size.Y / 2, math.ceil(mouse.Hit.Z))
    wait()
end

function onPurchase(t)
    local objects = game.ServerStorage:GetChildren()
    for i = 1, #objects do
        if objects[i].Name == selected.Value.Name then
            local a = objects[i]:Clone()
            a.Parent = game.Workspace:findFirstChild(plr.Name.."_kit")
            a:MoveTo(t.Position.X, t.Position.Y / 2, t.Position.Z)
            a.Name = "base"

            local b = Instance.new("BoolValue", a.Parent.owned)
            b.Name = "base"
            b.Value = true

            game.ServerStorage:FindFirstChild(plr.Name.."_stats").level = game.ServerStorage:FindFirstChild(plr.Name.."_stats").level + 1
        end
    end
end


script.Parent.Selected:connect(function(mouse)
    repeat wait() until menu.selected ~= nil
    onObjectSelected(mouse) 
end)

1 answer

Log in to vote
1
Answered by
Dummiez 360 Moderation Voter
10 years ago

Since you're running this from a HopperBin, and accepts LocalScripts as the only way to execute, you could rather parenting getting LocalPlayer, also I don't understand why you are naming PlayerGui when you are already getting the name?

Getting your player:

local plr = game.Players.LocalPlayer

Finding the PlayerGui:

print(plr.PlayerGui.Name)

EDIT: I think it works anyways.. lol

0
I see what you're getting at, but I need to be able to access ServerStorage with the script, and LocalScripts can't cheweydog 20 — 10y
0
How can your code access ServerStorage then? Running ServerScripts can't work on HopperBin as it was disabled because of exploits. Dummiez 360 — 10y
0
Crud. I forgot to test this in a live game. Thanks, I'll rewrite to work from a tool! cheweydog 20 — 10y
Ad

Answer this question