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

How do I get this to stop repeating onTouch?

How do I get this to only give the GUI once until the GUI doesnt exist in the player again?

GUI = script.Parent.ShopGUI:Clone()

function Touch(hit)
	local add = GUI:Clone()
	human = hit.Parent:FindFirstChild("Humanoid")
	player = game.Players:GetPlayerFromCharacter(hit.Parent)
	add.Parent = player.PlayerGui
end

script.Parent.Touched:connect(Touch)

3 comments

0

I see that you have commented on my answer but I deleted it. What were you going to say? I didn't get to see it. I deleted it because I thought you meant that you never wanted them to see the script again. You were too broad but I'm sorry I couldn't understand you. Also the thing that Alphawolvess has is called a Debounce. http://wiki.roblox.com/index.php?title=Debounce

0

I think I commented on a different answer

0

No but it said something in my notifications.

2 answers

✓ Accepted answer

Try this, We are using GetPlayerFromCharacter() To go to the person who touched the part, to their player and look inside of their StarterGui to see if ShopGUI exists. If it does then nothing happens, if it doesn't exist then something will happen.

local GUI = script.Parent.ShopGUI:Clone()

function Touch(hit)
	if game.Players.GetPlayerFromCharacter(hit.Parent).StarterGui.ShopGUI == nil then
		local add = GUI:Clone()
		human = hit.Parent:FindFirstChild("Humanoid")
		player = game.Players:GetPlayerFromCharacter(hit.Parent)
		add.Parent = player.PlayerGui
	else
		print(" ")
	end
end

script.Parent.Touched:connect(Touch)

If there's a problem, tell me and I'll fix it.

3 comments

0

This helped, and I will accept the answer, but first please fix: the else is backwards so it should be if gui = nil then print...else (run script)

0

Sorry, I made the syntax correct. If you do GUI (Your Variable) instead of ShopGUI, It will not work. Also, You can edit the else statement to do something else if you liked. Such as inserting a message to that player that he cannot get it twice.

0

I change ~= (Is not equal to) to == (is equal to)



local ting = 0 -- set a debouncer



GUI = script.Parent.ShopGUI:Clone() 02 03 function Touch(hit) -- when touched


if ting == 0 then -- if debouncer is off then t~~~~~~~~~~~~~~~~~ ``

ing = 1 -- make the debouner on so it cant be activated again
04	    local add = GUI:Clone()
05	    human = hit.Parent:FindFirstChild("Humanoid")
06	    player = game.Players:GetPlayerFromCharacter(hit.Parent)
07	    add.Parent = player.PlayerGui
08	end
09	 ting = 0 -- reset!
end
10	script.Parent.Touched:connect(Touch)

1 comment

0

im kinda confused cause its not in Lua form

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