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

Why does this script only work once or if player doesn't own game pass not at all?

Asked by
ElBamino 153
3 years ago

I wrote this script, it's on touch. If the player touches and owns game pass with leaderstats greater than or equal to 666 then, change the color of fire inside each part of character. I don't know why it doesn't work sometimes though and, I can't seem to get any output. I don't know how else to describe it or ask the question but, what seems to be the problem? It's only working once if the player owns the gamepass if not then not at all. If you could, can you please explain the problem and provide any links if needed? I appreciate the help. Sorry I've been asking so many questions lately! Thank you in advance as always.

Code I'm using is a Script inside of a Part inside of Workspace.

local debounce = true
local MarketplaceService = game:GetService("MarketplaceService")
local GamepassId = 17468467--my gamepassid
script.Parent.Touched:Connect(function(hit)
    if debounce == true and hit.Parent:FindFirstChild("Humanoid") then
        debounce = false
        local character = hit.Parent
        local player = game:GetService("Players"):GetPlayerFromCharacter(character)
        if player and MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassId) and player.leaderstats.Tix.Value >= 666 then
            local avatar = character:GetChildren()
            for _,t in pairs(avatar) do
                if t.ClassName == "Part" then
                    local fire = t.Fire
                    fire.Color = Color3.new(1,0,0)
                    fire.SecondaryColor = Color3.new(0,0,0)
                end
            end
        end
        wait(1)
    end
end)

1 answer

Log in to vote
1
Answered by
Rinpix 639 Moderation Voter
3 years ago
Edited 3 years ago

You didn't set debounce back to true.

if debounce == true and hit.Parent:FindFirstChild("Humanoid") then
    debounce = false
    local character = hit.Parent
    local player = game:GetService("Players"):GetPlayerFromCharacter(character)
    if player and MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassId) and player.leaderstats.Tix.Value >= 666 then
        local avatar = character:GetChildren()
        for _,t in pairs(avatar) do
            if t.ClassName == "Part" then
                local fire = t.Fire
                fire.Color = Color3.new(1,0,0)
                fire.SecondaryColor = Color3.new(0,0,0)
            end
        end
    end
    wait(1)
    debounce = true
end
1
Thank you so much, I didn't even notice that. I appreciate the help. Such a small thing but its a game changer lol. Thanks again. ElBamino 153 — 3y
0
Np lol. I do the exact same thing all the time. Rinpix 639 — 3y
Ad

Answer this question