Stupid CharacterAdded event is making stupid fireCrate event fire twice each time i run it.
This script basically loads the UI for a crate game. It needs to be inside a CharacterAdded function so the game works even after resetting or dieing.
Things I've Tried:
Using a debounce boolean - refuses to work: Still causes double firing and errors.
Using a RBXScriptConnection:Disconnect() - works perfectly except i cant run the event again without resetting my character.
Client (localscript) inside StarterPlayerScripts
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CharacterAdded:Connect(function()
local CrateClient = require(modules:WaitForChild("CrateClient")) -- modulescript
local fireCrate = events:WaitForChild("FireCrate") -- event
local crateconnect = nil -- RBXScriptConnection
crateconnect = fireCrate.OnClientEvent:Connect(function()
CrateClient:CrateFunctions(var, winner, number, crateconnect)
end)
end)
How do I re connect the function after its been disconnected (without just resetting my character)
This script is a lot bigger than what is shown here i reduced it to simplify the issue.
I will explain and/or post more code if required
** You are now Level 13! **