Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

3 comments

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?

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

0

I think I understand what you are trying to say, but unfortunately I can't say I understand this fully.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.