How to make a local script send data to server script with information on if a weapon does a critical or regular attack

Oh, I see, thanks for the tip!

You can add sanity checks to verify that an exploiter isn’t manipulating a client event in some way but as previously suggested most of the time you want to handle stuff on the server (if possible) as to circumvent any potential risk.

4 Likes

So if an exploiter wants something like infinite money, I just do this to check if the money given is something like 50?

if amountofmoney == 50 then

Exactly, but you should avoid client information as much as possible. Sanity checks are only needed if the client has to pass data.

An example of when a client would need to pass a value to the server is if you had a card game and a player wanted to play a card. When you give a player a card, keep a record of what cards the player currently has on the server. When the client fires the play card event, you can then use this record to check if the player has this card.

Example server code:

local playerCards = {} -- record of all players and the cards they own
local function giveCard(player, card)
    local cardsOwned = playerCards[player]
    if not cardsOwned then
        return
    end
    cardsOwned[card] = true -- player owns card
    updateCards:FireClient(plr, card) -- update the clients owner card info
    playerCards[player] = cardsOwned -- update the value
end

PlayerAdded:Connect(function(plr)
    playerCards[plr] = {} -- create a record for this player 
    giveCard(plr, ‘KingOfHearts’) -- give the player a card on join
end)

PlayerRemoving:Connect(function(plr)
    playerCards[plr] = nil -- player left, they no longer need a record
end)

PlayCard.OnServerEvent:Connect(function(plr, cardToPlay)
    if not playerCards[plr] then -- check if a record exists 
       return -- ignore request
    end
    if not playerCards[plr][cardToPlay] then
        return -- player does not own this card, ignore request 
    end
    -- player owns card, continue
end
3 Likes