Can you stop there being more than one instance of the same remote event for a player at a time?
Asked by
4 years ago Edited 4 years ago
I'm having an issue, and I can't seem to find any information on how to fix it online. I'm trying to make a loadout script, where when a player clicks on a GUI element, they are given the corresponding weapon upon respawning. My issue is, if they click a whole bunch of different buttons, it calls a whole bunch of separate remote events which all run the same serverside script, meaning that when they respawn they will have many weapons instead of only one. Is there a way to put something at the beginning of the serverside script that says; "If there are other instances of this script running (for this player), stop those instances, and then run the script?"
Clientside Code:
01 | local weaponButton = script.Parent |
03 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
04 | local weaponLevelCheckFunction = ReplicatedStorage:WaitForChild( "WeaponLevelCheckFunction" ) |
05 | local weaponLevelRequested = 0 |
07 | weaponButton.MouseButton 1 Up:Connect( function () |
08 | print ( "Loadout Change Request Received" ) |
09 | weaponLevelCheckFunction:InvokeServer(weaponLevelRequested) |
Serverside Code:
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local WeaeponLevelCheckFunction = ReplicatedStorage:WaitForChild( "WeaponLevelCheckFunction" ) |
04 | WeaeponLevelCheckFunction.OnServerInvoke = function (player, levelRequirement) |
06 | player.CharacterAdded:Wait() |
07 | local toolToEquipFolder = game:GetService( "ServerStorage" ):WaitForChild( "SpoonModelStorage" ):WaitForChild(levelRequirement) |
08 | local toolToEquip = toolToEquipFolder:FindFirstChildWhichIsA( "Tool" ):Clone() |
09 | local playerLevel = player.leaderstats.Level.Value |
11 | if playerLevel > = levelRequirement then |
15 | print ( "Tool Equipped" ) |
17 | print ( "Player level is not high enough to equip this item" ) |