this shouldnt do anything since equippedAnAura is reseted to false everytime you roll but ill try anyways
it doesnt work:
I could be wrong but I’m pretty sure you’re having a connection stack issue.
Every time rollEvent.OnClientEvent
fires you nest fresh MouseButton1Click
connections inside it, after a few rolls you’re sitting on a stack of old handlers that still reference the previous result/chance
variables
Once you press Skip, those stale functions ‘short-circuit’ the new ones, so the Equip button seems to “stop working”.
Updated script that disconnects old button handlers before making new ones, let me know how this works out:
local rp = game:GetService("ReplicatedStorage")
local ss = game:GetService("SoundService")
local equipEvent = rp.EquipAura
local rollEvent = rp.Roll
local mainEvent = rp.MainEvent
local button = script.Parent
local Auras = require(rp:WaitForChild("Auras"))
local invFrame = script.Parent.Parent.Parent:WaitForChild("Tabs").Inventory:WaitForChild("ScrollingFrame")
local collectionFrame = script.Parent.Parent.Parent:WaitForChild("Tabs").Collection:WaitForChild("ScrollingFrame")
local exampleBtn = invFrame:WaitForChild("Example")
local db = false
local specialChance = 1000
local cutsceneChance = 10000
local equipConn
local skipConn
local function auraTick(nameTxt, chanceTxt)
local aura = Auras[math.random(1, #Auras)]
nameTxt.Text = tostring(aura.name)
nameTxt.Position = UDim2.fromScale(.5, .46)
nameTxt.TextColor3 = aura.color
nameTxt.FontFace = aura.font
game.TweenService:Create(nameTxt, TweenInfo.new(.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Position = UDim2.fromScale(.5, .48)}):Play()
chanceTxt.Text = "1 in " .. tostring(aura.chance)
chanceTxt.Position = UDim2.fromScale(.5, .515)
chanceTxt.TextColor3 = aura.color
chanceTxt.FontFace = aura.font
game.TweenService:Create(chanceTxt, TweenInfo.new(.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Position = UDim2.fromScale(.5, .535)}):Play()
ss.Tick:Play()
end
button.MouseButton1Click:Connect(function()
if not db and not game.Players.LocalPlayer:GetAttribute("AutoRoll") then
db = true
rollEvent:FireServer()
end
end)
rollEvent.OnClientEvent:Connect(function(result, chance, color, font)
local blackFrame = script.Parent.Parent.Frame
local star = blackFrame.Star
local vignette = blackFrame.Vignette
local nameTxt = blackFrame.AuraName
local chanceTxt = blackFrame.AuraChance
local skipButton = blackFrame.SkipAura
local equipButton = blackFrame.EquipAura
if equipConn then equipConn:Disconnect() end
if skipConn then skipConn:Disconnect() end
local cooldown = game.Players.LocalPlayer:GetAttribute("Cooldown")
blackFrame.Visible = true
for _ = 1, 4 do
auraTick(nameTxt, chanceTxt)
task.wait(cooldown - 0.25)
end
nameTxt.Text = tostring(result)
nameTxt.Position = UDim2.fromScale(.5, .46)
nameTxt.TextColor3 = color
nameTxt.FontFace = font
game.TweenService:Create(nameTxt, TweenInfo.new(.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Position = UDim2.fromScale(.5, .48)}):Play()
chanceTxt.Text = "1 in " .. tostring(chance)
chanceTxt.Position = UDim2.fromScale(.5, .515)
chanceTxt.TextColor3 = color
chanceTxt.FontFace = font
game.TweenService:Create(chanceTxt, TweenInfo.new(.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Position = UDim2.fromScale(.5, .535)}):Play()
ss.Tick:Play()
task.wait(cooldown - 0.25)
if chance >= specialChance and chance < cutsceneChance then
blackFrame.Transparency = 0
vignette.Visible = true
vignette.ImageTransparency = 1
vignette.ImageColor3 = color
game.TweenService:Create(vignette, TweenInfo.new(4, Enum.EasingStyle.Sine, Enum.EasingDirection.In), {ImageTransparency = 0}):Play()
task.wait(4)
ss.NormalBoom:Play()
blackFrame.Transparency = 0.45
vignette.ImageColor3 = Color3.new(1, 1, 1)
vignette.ImageTransparency = 1
elseif chance >= cutsceneChance then
ss.Shine:Play()
blackFrame.Transparency = 0
star.Visible = true
vignette.Visible = true
star.ImageColor3 = color
vignette.ImageColor3 = color
vignette.ImageTransparency = 0
star:TweenSize(UDim2.fromScale(0.5, 0.5), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 4)
game.TweenService:Create(star, TweenInfo.new(8, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Rotation = math.random(360, 540)}):Play()
task.wait(4)
star:TweenSize(UDim2.fromScale(1, 1), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 4)
task.wait(4)
ss.SpecialBoom:Play()
blackFrame.Transparency = 0.45
vignette.Visible = false
vignette.ImageColor3 = Color3.new(1, 1, 1)
vignette.ImageTransparency = 1
star.Visible = false
star.Size = UDim2.fromScale(1, 1)
star.Rotation = 0
star.ImageColor3 = Color3.new(1, 1, 1)
end
local function finishRoll()
blackFrame.Visible = false
skipButton.Visible = false
equipButton.Visible = false
script.Parent.Frame.Transparency = 0.45
script.Parent.Frame.Size = UDim2.fromScale(1, 1)
game.TweenService:Create(script.Parent.Frame, TweenInfo.new(cooldown), {Transparency = 1, Size = UDim2.fromScale(0, 1)}):Play()
task.wait(cooldown)
db = false
end
local function createInventoryButton()
local btn = exampleBtn:Clone()
btn.Parent = invFrame
btn.Visible = true
btn.Text = tostring(result)
btn.TextColor3 = color
btn.UIStroke.Color = color
btn.FontFace = font
btn.Chance.Value = chance
local auraBtn = collectionFrame[tostring(result)]
auraBtn.Locked.Value = false
auraBtn.Text = tostring(result)
auraBtn.TextColor3 = color
auraBtn.FontFace = font
auraBtn.Interactable = true
end
if tonumber(game.Players.LocalPlayer:GetAttribute("AutoSkip")) < chance then
if tonumber(game.Players.LocalPlayer:GetAttribute("AutoEquip")) > chance or game.Players.LocalPlayer.Auras.Value == game.Players.LocalPlayer.Max.Value then
skipButton.Visible = true
equipButton.Visible = true
else
equipEvent:FireServer(result)
mainEvent:FireServer(1, "aurasValue")
createInventoryButton()
mainEvent:FireServer(1, "roll")
finishRoll()
end
else
mainEvent:FireServer(1, "roll")
finishRoll()
end
local equippedAnAura = false
local equipWarned = false
local showedEquipWarning = false
skipConn = skipButton.MouseButton1Click:Connect(function()
if chance > specialChance and not showedEquipWarning then
blackFrame.Warning.Visible = true
showedEquipWarning = true
return
end
mainEvent:FireServer(1, "roll")
finishRoll()
end)
equipConn = equipButton.MouseButton1Click:Connect(function()
if game.Players.LocalPlayer.Auras.Value ~= game.Players.LocalPlayer.Max.Value and not equippedAnAura then
equippedAnAura = true
equipEvent:FireServer(result)
mainEvent:FireServer(1, "aurasValue")
createInventoryButton()
mainEvent:FireServer(1, "roll")
finishRoll()
return
end
if game.Players.LocalPlayer.Auras.Value == game.Players.LocalPlayer.Max.Value and not equipWarned then
equipWarned = true
return
end
if equipWarned then
blackFrame.Warning.Visible = true
blackFrame.Warning.Text = "Not enough storage! (click equip again to overwrite a random aura)"
equipWarned = false
showedEquipWarning = true
return
end
if showedEquipWarning then
for _, child in ipairs(invFrame:GetChildren()) do
if child:IsA("TextButton") then
child:Destroy()
mainEvent:FireServer(-1, "aurasValue")
break
end
end
equipEvent:FireServer(result)
createInventoryButton()
mainEvent:FireServer(1, "roll")
finishRoll()
end
end)
end)
thx, not only did you fix the issue, you also improved my code, thank you!
Glad to see it got fixed, if you really want to improve you code base, you should remove game.TweenService
and replace it with local TweenService = game:GetService("TweenService")
then remove all the game.Players.LocalPlayer
and replace it with local Player = game:GetService("Players").LocalPlayer
You could also split your code into functions for when handling the MouseButton1Clicks, always remember to refactor your code so its more readable to you in the future, but it doesnt need to be perfect!
yeah, i should remember that, thanks!
I’ve just found another problem with the script, now what happens is everytime i click the equip button it clones the aura twice (like the problem i described firstly), but now theres no need to press the skip button before, i’ve added some things to the script but not that many.