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

How do I get this to stop repeating onTouch?

Asked by 9 years ago

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)
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 EzraNehemiah_TF2 3552 — 9y
0
I think I commented on a different answer BSIncorporated 640 — 9y
0
No but it said something in my notifications. EzraNehemiah_TF2 3552 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

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.

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) BSIncorporated 640 — 9y
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. alphawolvess 1784 — 9y
0
I change ~= (Is not equal to) to == (is equal to) alphawolvess 1784 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.



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)

0
im kinda confused cause its not in Lua form BSIncorporated 640 — 9y

Answer this question