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

ScreenGui opens onTouch but only one time? Why?

I have several morphs in my game and if you step on a part, you'll turn into that morph and a custom gui will show up for whichever character you choose. However, this only works one time. If you restart/die and pick a character again then the Gui wont show up at all. I'm using FilteringEnabled and I'm not getting any error messages.

local menu = script.Parent.CharacterGui

local function onTouched(hit)
    if (game.Players:GetPlayerFromCharacter(hit.Parent)) then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if not player.PlayerGui:findFirstChild("CharacterGui") then 
			menu:Clone().Parent = player.PlayerGui
			wait()
		end
	end
end

script.Parent.Touched:connect(onTouched)

In studio mode, this script works 100% of the time so I can't figure out what the problem is.

1 comment

0

The Gui is in the part that you touch. I want it to transfer to the PlayerGui.

1 answer

This should work:

local menu = script.Parent:WaitForChild('CharacterGui')

local function onTouched(hit)
    if (game.Players:GetPlayerFromCharacter(hit.Parent)) then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if not player.PlayerGui:FindFirstChild("CharacterGui") then
           local menuclone = menu:Clone()
           menuclone.Parent = player.PlayerGui
            wait()
        end
    end
end

script.Parent.Touched:connect(onTouched)

If this does help, please press the ^ icon and accept the answer, if it doesn't, please let me know in this answer's comments and I will alter it.

4 comments

0

Hmm, no this is giving me the same result :(

0

I made an edit, it should work now

0

It still wont work, sorry

0

You shouldn't just give him the answer, you should help him complete it. He is going to get no where if you just give it to him.

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