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

Activated door based on how many cans you have?

I have a gui which basically acts like leaderstats. I have a door which allows entrance by having a gamepass though I'm not sure what values to change in order to base it on the gui leaderstats. So for a door I want to change the amount needed to 5 or 6 then if they have it then they can come.

Gui Leaderstats:

fol = Instance.new("Folder", game.Workspace)
fol.Name = "Data"
game.Players.PlayerAdded:connect(function(plr)
plrfol = Instance.new("Folder", fol)
plrfol.Name = plr.Name
val = Instance.new("NumberValue", plrfol)
val.Value = 0
val.Name = "Socks"
end)

game.Players.PlayerRemoving:connect(function(plr)
fol[plr.Name]:Destroy()
end)


Door Script:

local debounce = false 

script.Parent.Touched:connect(function(hit)
  	if debounce == false then 
		wait()
		debounce = true 
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local gamepassId = script.Parent.GamepassId
		local marketplaceservice = game:GetService("MarketplaceService")
		if player and marketplaceservice:PlayerOwnsAsset(player, gamepassId.Value) then
			script.Parent.CanCollide = false
			wait(.5) 
			script.Parent.CanCollide = true
		end
	end
	wait(2)
	debounce = false 
end)

1 answer

✓ Accepted answer

Door Script:

local debounce = false 

script.Parent.Touched:connect(function(hit)
	if debounce == false then 
		wait()
		debounce = true 
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player and workspace.Data[player.Name].Socks.Value >= 5 then --if they have 5 or more Socks
			script.Parent.CanCollide = false
			wait(.5) 
			script.Parent.CanCollide = true
		end
		--I placed the debounce inside the if statement, so that it only gets reset by the function call that set it
		wait(2)
		debounce = false
	end
end)

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