I just found this roblox scripting help page and I found it interested. I want to write this question because I didn't know how to fix this mistake and make it more simple. Here is the code:

local debounce = true

function onTouched(part)
	if part.Parent == nil then return end
	local thisplr = game.Players:findFirstChild(h.Parent.Name)	
            if (h~=nil) then
		if h.Health == 0 then return end
		local thisplr = game.Players:findFirstChild(h.Parent.Name)
		if (thisplr~=nil) then
				local cash = thisplr:findFirstChild(script.Parent.testobjvalue.Value)
				if (cash == nil) and (debounce == true) then
					debounce = false
					thisplr.leaderstats.Test.Value = thisplr.leaderstats.Test.Value + 1
					local c = Instance.new("ObjectValue")
					c.Parent = thisplr
					if thisplr == nil then return end
					c.Name = script.Parent.Parent.Name
					local h = thisplr.PlayerGui.Message.msg
					h.Visible = true
					wait(4)
					h.Visible = false
					debounce = true					
				else
					 if (debounce == true) then
					debounce = false
					local h = thisplr.PlayerGui.Message.msgac
					h.Visible = true
					wait(4)
					h.Visible = false
					debounce = true
					end					
				end
		end
	end
end

script.Parent.Touched:connect(onTouched)

Basically this script when someone touchs a Part the player will be awarded with 1 point in the leaderboard and a message shows up, What it doesn't do it is that if the players picks it again it will be awarded the point again, and this shouldn't happen, instead, it should say to the player that you alredy got that

I would appreciate an hand, thanks ^^

(The GUIs exists)

6 comments

0

The debounce should really be set at the start and end of the script.

0

It actually does?

0

This is lua, not JavaScript. You don't need the parentheses around the conditional in if statements. For example, "if (h ~= nil) then" should really be just "if h ~= nil then".

0

Will try if that will fix something, sorry for that, I just use a lot of java :P

0

Doesn't solve Anything.

0

Mh... Ok so I find a method to simple it but it still doesn't do the thing it should do