#stupid rbxscriptconnection shit

1 messages · Page 1 of 1 (latest)

frozen inlet
#

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

empty harborBOT
#

studio** You are now Level 13! **studio

spring palm
empty harborBOT
#

studio** You are now Level 1! **studio

frozen inlet
# spring palm put crateconnect outside the characteadded and put ```lua if crateconnect then ...

i need to call it multiple times which means i don't think this will work

It looks like this

function CrateClient:CrateFunctions(var, winner, number, crateconnect)
  if var == "pending" then
    game.Workspace.Interact.Crates.Basic.Click.ProximityPrompt.Enabled = false
    purchaseframe.Visible = true
    purchaseframe:WaitForChild("Text").Text = "Play Basic Crate?"
    purchaseframe:WaitForChild("Coins").Text = "-1000"
    purchaseframe:WaitForChild("Robux"):WaitForChild("Amount").Text = "50"

  elseif var == "timer" then
    local timer = crateframe:FindFirstChild("Timer")
    if number == 10 then
        timer.Text = `0:{number}`
    else
        timer.Text = `0:0{number}`
    end

  elseif var == "winner" then
    CrateClient.showitem(winner, claimGui)

  elseif var == "stop" then
    CrateClient.stopfunction(crateframe, rollFrame, fireCrate, tween1)

  elseif var == "close" then
    workspace.Interact.Crates.Basic.Click.ProximityPrompt.Enabled = true
    crateconnect:Disconnect() -- Only once the game is closed does the connection get disconnected()

  elseif var == "robuxSuccess" then
    purchaseframe.Visible = false

  else
    warn("error")
    crateconnect:Disconnect()
  end
end 
frozen inlet
frozen inlet
#

@spring palm I tried it but doesn't work sadly, tho this might be on the right track

frozen inlet
#

i will read any ideas in the morning its 4am here

mortal cliff
mortal cliff
#

if u want to run the function again just move everything to its own function and call that inside characterAdded and you can call that func later asw

#

think im misunderstanding wym by i cant run event again

frozen inlet
#

can i do 'if crateconnect:Disconnect() then run the function again

mortal cliff
frozen inlet
#

so ill have to use some kind of bindable event because i do need the characteradded part -> this is because im not only doing UI's and i cant just disable reset on death

mortal cliff
#

and then call that inside characteradded abd turn off resetonspawn

#

or am i misunderstanding

frozen inlet
#

hmmm maybe

frozen inlet
# mortal cliff or am i misunderstanding

you;re all goods brutha i dont think i coded it very well tbh the problem is that i dont really want to recode too much as ive been working on this game for months and if i move one thing i have to move everything and i hate wasting too much time

#

i shoulf of just left it inside starter gui but i decided to put everything into modules to attempt to 'make it cleaner'

frozen inlet
#

yes absolutely especially with the tutorial level

mortal cliff
#

but you gotta typically plan code first before you use modiles

#

or it can become very spaghetti logic

frozen inlet
#

i made a tutorial level and i had to split up stuff for it to work

#

ive been coding for about 8 months and started this game like 6 months ago

#

so i was learning as i was making the game

mortal cliff
#

did you just split it on the go

#

or did u have a pretty decent idea on what modules will handle what

frozen inlet
#

nah i made everything work first and then spent 2 days moving everything after 90% of the game was done

#

so it was VERY spaghetti

#

now its slightly less spaghetti

mortal cliff
#

yeah thats an issue that you learn with experience

#

spaghetti logic is mad annoying to work with

frozen inlet
#

ofc i understand i will get better over time i just want to get something out soon im setting myself til october 30th to get something shipped even if its kinda still beta

#

i want to be able to expand it easier so theres items you can win in the crate game so i made everything into a module full of every item and an assets folder and i just add the item model to that and make a new item inside the module kinda thing

mortal cliff
empty harborBOT
#

studio** You are now Level 5! **studio

mortal cliff
frozen inlet
# mortal cliff spaghetti logic is mad annoying to work with

sometimes i cant do much to fix it... specific items have similar but also different functions like one is a drink that is one time use and another item is a cup you can constantly refill ... both copy SOME code from eachother such as the drink animations etc... but im still like if item.name == to this specific item then do this etc...

mortal cliff
frozen inlet
mortal cliff
#

you dont need to abstract every item that has any similarity to each other but really depends on what type of items you got

mortal cliff
#

i still dont have a clear understnad of it

mortal cliff
frozen inlet
#

okay that might help so far this is what it looks like hold on

#

i have to be careful how much i share cuz my gf designed the game map and she told me not to show the map or too much of what the game is

#

this is what i have so far

#

the piano handler was actually just the basic playable piano model you can get from toolbox and it was actually the stupidest code i ever seen i hated sorting it out

#

i ended up just leaving the GUI script for the piano inside startergui