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

Activated door based on how many cans you have?

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

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)
Ad

Answer this question