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

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

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

✓ Accepted answer

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

2 comments

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.

0

Np lol. I do the exact same thing all the time.

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