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

When a player steps on a Part, GUI appears but only once?

Asked by
Vxpper 101
4 years ago

How can I fix this? I have a script that once a player steps on a Part, it opens a GUI but, it only opens once. I have a localscript that fires an event which adds coins to the players inventory, but, the GUI only appears once, how do I change that so whenever they step on the part and the collected value is false, it opens how do I do this?

local guiname = "RewardGUI"

script.Parent.Touched:connect(function(hit)
    if hit == nil then return end
    if hit.Parent == nil then return end

    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player ~= nil and player.collected.Value == false then
        if player:FindFirstChild("PlayerGui") then
            if not player.PlayerGui:FindFirstChild(guiname) then
                local ui = script.Parent:FindFirstChild(guiname):clone()
                ui.Parent = player.PlayerGui            
            end
        end
    end
end)

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

You didn't destroy the GUI, you just add it and done, and if the localscript deletes it you have to do it in a script because localscripts changes like destroy are not replicated because of FilteringEnabled, also if you don't delete it it won't work because in the line 10 you are checking if the gui is there, Hope it works! :D

local guiname = "RewardGUI"

script.Parent.Touched:connect(function(hit)
    if hit == nil then return end
    if hit.Parent == nil then return end

    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player ~= nil and player.collected.Value == false then
        if player:FindFirstChild("PlayerGui") then
            if not player.PlayerGui:FindFirstChild(guiname) then
                local ui = script.Parent:FindFirstChild(guiname):clone()
                ui.Parent = player.PlayerGui
wait(2) -- change it for delay

ui:Destroy()            
            end
        end
    end
end)
0
Okay, final question. So this is for a daily reward, when the player leaves and joins back they can go over and the GUI will appear again, how do I fix this? Vxpper 101 — 4y
0
store its name and check if the name was stored or not if it wasn't then make the gui appear if it was then it won't appear maumaumaumaumaumua 628 — 4y
0
I think I understand what you are trying to say, but unfortunately I can't say I understand this fully. Vxpper 101 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

You could just use the .enabled property and set it to true/false to whether it comes up. That's what I use to make the guis pop up and off.

Answer this question