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

My Shop Gui Won't Open If You Step On It Again!?

Asked by 4 years ago

After you step on the Part that makes the shop open, it opens once. If you try again it won't open??

Script In Part

CanOpen = true

function onTouched(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
        if CanOpen == true then
            local shop = plr:WaitForChild("PlayerGui").ShopUI.Shop
            shop.Visible = true
            CanOpen = false
            wait(1)
            CanOpen = true
        end
    end
end

script.Parent.Touched:connect(onTouched)


3 answers

Log in to vote
0
Answered by
Alphexus 498 Moderation Voter
4 years ago

Your real problem is that you are changing the visibility from the Client and also from the Server. I think you are opening it, but then using a button to close the GUI, but that changes the visibility for the Client. The Server still sees the GUI open.

0
I suggest using a RemoteEvent and opening it from the client. Alphexus 498 — 4y
Ad
Log in to vote
-1
Answered by 4 years ago

Hi! I'm lolol1901, hoping to fix your issue. Any problems? Worked? Something else? Please comment on this reply right away so I can help you or make sure it worked fine.


First of all, I suggest you replace CanOpen by debounce, but it's 100% your choice.


Second of all, nice indent. First time I see someone using indents goodly.


Lastly, here's what I would've put in your position. This script is fully commented (like all my answers.) I'm also going to space it so it's easy to read.

db = true -- db short for debounce, replacing your CanOpen bool variable.

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid") then -- Why didn't I create the player variable immediately? An accessory might've touched the part. I need to make sure whatever touched was part of a player, and if it is an accessory.

        local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- player var

        if db == true then -- Of course, an if statement to make sure the cooldown is off.

            db = false -- I prefer activating the cooldown first things first in case of something.
            local shop = player:WaitForChild("PlayerGui").ShopUI.Shop -- shop var

            shop.Visible = true -- Make it visible

            wait(1) -- Of course, wait so the debounce works.

            db = true -- Cooldown Over

            -- Small note: Make sure you have something that disables the GUI. I'm thinking you have a button inside the GUI that closes it.

        end
    end
end)

Please upvote this if it is a good solution or if it worked well!

0
This is a stolen comment from another issue. Please! Make your own for once and not just look it up. Lakodex 711 — 4y
0
stolen? royaltoe 5144 — 4y
0
also canOpen is the same as debounce. debounce is just the term for it. youre also not checking if the player exists royaltoe 5144 — 4y
Log in to vote
-1
Answered by 4 years ago

You can't access a playersgui with a normal script.


CanOpen = true function onTouched(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then if CanOpen == true then local shop =game.ServerStorage.ShopUI.Shop:Clone() shop.Parent = plr.PlayerGui shop.Visible = true CanOpen = false wait(1) CanOpen = true end end end script.Parent.Touched:connect(onTouched)
0
You actually can access PlayerGui from a server script. It just isn't recommended. I suggest you do your research before making claims like that. Alphexus 498 — 4y
0
well sorry that im late but from my experience i couldn't access it and bye HappyTimIsHim 652 — 4y

Answer this question