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

Which way of using BindableEvents is better?

I'm working on a save script that updates my datastore whenever an event is triggered by one of the various outside scripts. I'm just unsure of which way I should code the BindableEvents. Here are my options:

SaveAchievementEvent.Event:Connect(function(Key, UpdatedValue)
	UserData.Achievements[Key] = UpdatedValue
	AchieveData:SetAsync(UserData.Achievements)
end)

SaveCurrencyEvent.Event:Connect(function(Key, UpdatedValue)
	UserData.Currency[Key] = UpdatedValue
	CurrencyData:SetAsync(UserData.Currency)
end)

"etc..."

or should I combine them into one and just pass the values that I need from the scripts that are firing the event such as:

SaveEvent.Event:Connect(function(TopKey, BottomKey, UpdatedValue, StatData)
	UserData[TopKey][BottomKey] = UpdatedValue
	StatData:SetAsync(UserData[TopKey])
end)

I'm asking this for a couple of reasons. First, will it create some kind of bottleneck if I combine the Events into one (I'm worried if the event is passed too much data too quickly)? Second, anything else unforeseen that I'm unaware of?

*It's important to note that I'm using Datastore2, so simply passing a table isn't an option because I MUST use string keys (Datastore2 requires this, and the documentation of BindableEvents states that string keys aren't allowed to be passed)

1 answer

I dont know why you should do that seperate. I would combine them, since its the same key. I dont have much context, but if it is the same key, combine them.

2 comments

0

The keys are separate. Instead of having: UserData.Currency or UserData.Achievements I will pass the string value of "Currency" or "Achievements" from a different script to be applied to this universal save event.

0

Then I would seperate the events.

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