I have a leaderstats script that depends on this bindable event and the value gets added twice. Is there any way to fix this?
Here is the script:
-- Variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local OnButtonClick = ReplicatedStorage.RemoteEvents.OnButtonClick
local OnButtonClick2 = ReplicatedStorage.RemoteEvents.OnButtonClick2
local SecretValueIncrease = ServerStorage.BindableEvents.SecretValueIncrease
local debounce = false
local SecretTrue = false
-- OnButtonClick
OnButtonClick.OnServerEvent:Connect(function(player)
local PlayerGui = player.PlayerGui
local AllGUIs = PlayerGui.AllGUIs
local InfoLabel = AllGUIs.UIElements.InfoLabel
local button = AllGUIs.UIElements.ChangeColor
-- EnableOrDisable Function
local function EnableOrDisable(target, argument)
if argument == "Enable" then
target.Enabled = true
elseif argument == "Disable" then
target.Disabled = true
end
end
-- TypewriterEffect Function
local function TypewriterEffect(text)
for i = 1, #text do
InfoLabel.Text = string.sub(text, 1, i)
task.wait(.05)
end
end
if not debounce then
debounce = true
local luck = math.random(1, 1000)
if luck == 1 then
SecretTrue = true
end
task.wait(.5)
debounce = false
end
if SecretTrue then
EnableOrDisable(AllGUIs.LocalScripts.OnButtonClickRemoteEvent, "Disable")
EnableOrDisable(AllGUIs.LocalScripts.RGB_RNG, "Disable")
EnableOrDisable(AllGUIs.LocalScripts.TextLabelEditor, "Disable")
SecretValueIncrease:Fire(player) -- Here is the bindable event.
InfoLabel:TweenSize(
UDim2.new(0, 475, 0, 70),
Enum.EasingDirection.In,
Enum.EasingStyle.Sine,
.7,
true
)
InfoLabel.BackgroundColor = BrickColor.new("White")
TypewriterEffect(-- Secret)
task.wait(1.5)
TypewriterEffect(-- Secret)
task.wait(.25)
EnableOrDisable(AllGUIs.LocalScripts.OnButtonClick2RemoteEvent, "Enable")
OnButtonClick2.OnServerEvent:Connect(function()
EnableOrDisable(AllGUIs.LocalScripts.OnButtonClick2RemoteEvent, "Disable")
if not debounce then
debounce = true
TypewriterEffect(-- Secret)
task.wait(1.5)
TypewriterEffect(-- Secret)
task.wait(1.5)
TypewriterEffect(-- Secret)
task.wait(1.5)
TypewriterEffect(-- Secret)
task.wait(1.5)
-- Secret
debounce = false
end
end)
end
end)
Leaderstats script: (Not the whole one)
-- SecretValue
SecretValueIncrease.Event:Connect(function(player)
player:WaitForChild("leaderstats"):WaitForChild("???").Value += 1
end)