Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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:

local weaponButton = script.Parent

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local weaponLevelCheckFunction = ReplicatedStorage:WaitForChild("WeaponLevelCheckFunction")
local weaponLevelRequested = 0 -- Change me based on the level of the weapon

weaponButton.MouseButton1Up:Connect(function()
    print("Loadout Change Request Received")
    weaponLevelCheckFunction:InvokeServer(weaponLevelRequested) -- Invokes the function and sends the requested level
end)

Serverside Code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WeaeponLevelCheckFunction = ReplicatedStorage:WaitForChild("WeaponLevelCheckFunction")

WeaeponLevelCheckFunction.OnServerInvoke = function(player, levelRequirement) -- Fires when the player clicks on an item in the loadout GUI

    player.CharacterAdded:Wait() -- Wait for character to respawn
    local toolToEquipFolder = game:GetService("ServerStorage"):WaitForChild("SpoonModelStorage"):WaitForChild(levelRequirement) -- Selects which tool to grab based on level requirement
    local toolToEquip = toolToEquipFolder:FindFirstChildWhichIsA("Tool"):Clone() -- Grabs the tool inside the previously selected folder
    local playerLevel = player.leaderstats.Level.Value -- Finds the player's level (Serverside)

    if playerLevel >= levelRequirement then 

        --
        toolToEquip.Parent = player.Backpack 
        print("Tool Equipped")
    else
        print("Player level is not high enough to equip this item")
    end
end

0
please include your code Cynical_Innovation 595 — 4y
0
I have updated the post to include the code (Apologies for not doing so initially, I am new to the platform) FlashHawkAssassin 0 — 4y

Answer this question