Skip to content
TheChatArchiveThe Chat Archive
grok-3-mini-high· xAIHugging Face LMArena Human Preference 140K

can u make me a script for lua(roblox) where when u kill another player u get 100 Coins

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-sonnet-4-20250514’s answer.
  1. User

    can u make me a script for lua(roblox) where when u kill another player u get 100 Coins

  2. Assistant

    Below is a Lua script for Roblox that awards 100 Coins to a player when they kill another player. This script assumes you're working in a Roblox game where:

    • Players have a "leaderstats" folder with a "Coins" value (e.g., an IntValue) to track coins.
    • The game tracks the killer by setting an attribute on the victim's Humanoid (e.g., "LastAttacker") when damage is dealt. This is common in Roblox PvP games, but you'll need to implement that logic in your tools or damage-dealing scripts.

    For example, in your weapon/tool scripts (on the server), when a player damages another player, add a line like:

    humanoid:SetAttribute("LastAttacker", attackerPlayer.Name)
    

    This script will then use that attribute to detect the killer and award coins.

    Important Notes:

    • Place this script in ServerScriptService for it to run on the server (it's a server script).
    • This script only handles the coin awarding part. You must ensure that damage-dealing scripts (e.g., in tools) set the "LastAttacker" attribute.
    • If your game doesn't already track attackers, this script won't work on its own. You'd need to add that functionality.

    Here's the script:

    -- Server Script for awarding coins on player kills
    -- Place this in ServerScriptService
    
    local Players = game:GetService("Players")
    
    -- Function to handle when a player's character is added
    local function onCharacterAdded(character)
        local humanoid = character:WaitForChild("Humanoid")
        
        -- Connect to the Humanoid's Died event
        humanoid.Died:Connect(function()
            local lastAttackerName = humanoid:GetAttribute("LastAttacker")  -- Get the last attacker from the attribute
            if lastAttackerName then
                local lastAttackerPlayer = Players:FindFirstChild(lastAttackerName)  -- Find the player by name
                if lastAttackerPlayer and lastAttackerPlayer.Character and lastAttackerPlayer.Character:FindFirstChild("Humanoid") then  -- Ensure the player still exists
                    -- Award 100 coins to the killer
                    local leaderstats = lastAttackerPlayer:FindFirstChild("leaderstats")
                    if leaderstats then
                        local coins = leaderstats:FindFirstChild("Coins")  -- Assuming "Coins" is an IntValue
                        if coins then
                            coins.Value = coins.Value + 100  -- Add 100 coins
                            print(lastAttackerPlayer.Name .. " has been awarded 100 coins for killing " .. character.Name)
                        else
                            warn("Coins value not found in leaderstats for player: " .. lastAttackerPlayer.Name)
                        end
                    else
                        warn("Leaderstats not found for player: " .. lastAttackerPlayer.Name)
                    end
                end
            else
                print(character.Name .. " died, but no attacker was recorded.")
            end
        end)
    end
    
    -- Connect to new players joining
    Players.PlayerAdded:Connect(function(player)
        player.CharacterAdded:Connect(onCharacterAdded)
        
        -- If the player already has a character (e.g., they joined before the script ran)
        if player.Character then
            onCharacterAdded(player.Character)
        end
    end)
    
    -- Handle players already in the game
    for _, player in pairs(Players:GetPlayers()) do
        if player.Character then
            onCharacterAdded(player.Character)
        end
        player.CharacterAdded:Connect(onCharacterAdded)
    end
    

    How to Set This Up in Your Game:

    1. Create Leaderstats for Players:

      • In another server script (e.g., in ServerScriptService), add leaderstats when a player joins:
        game.Players.PlayerAdded:Connect(function(player)
            local leaderstats = Instance.new("Folder")
            leaderstats.Name = "leaderstats"
            leaderstats.Parent = player
            
            local coins = Instance.new("IntValue")
            coins.Name = "Coins"
            coins.Value = 0  -- Starting coins
            coins.Parent = leaderstats
        end)
        
    2. Track the Attacker in Your Damage-Dealing Scripts:

      • For example, in a server script inside a tool (like a sword), add this when the tool damages another player:
        local tool = script.Parent  -- The tool
        tool.Activated:Connect(function()
            -- Assuming you have code to detect hits (e.g., using Touched event)
            tool.Handle.Touched:Connect(function(hit)
                local character = hit.Parent
                if character and character:FindFirstChild("Humanoid") then
                    local humanoid = character.Humanoid
                    if humanoid and humanoid.Health > 0 then  -- Only if the target is alive
                        local player = game.Players:GetPlayerFromCharacter(tool.Parent)  -- The player holding the tool
                        if player then
                            humanoid:SetAttribute("LastAttacker", player.Name)  -- Set the attacker attribute
                            -- Your damage code here, e.g., humanoid:TakeDamage(20)
                        end
                    end
                end
            end)
        end)
        
    3. Test the Script:

      • Playtest your game in Roblox Studio.
      • Make sure players can kill each other (e.g., via tools or weapons).
      • Verify that the "LastAttacker" attribute is being set correctly.
      • Check the player's leaderstats to see if coins are added.

    If you run into issues (e.g., the attribute isn't being set), let me know more about your game's setup, and I can help refine this! 😊

  3. User

    i use acs

  4. Assistant

    It looks like you mentioned "i use acs," which I assume refers to the Advanced Combat System (ACS) in Roblox. ACS is a popular combat framework that handles things like damage, hits, and kill detection, often used in PvP games. If that's what you mean, we can adapt the script I provided earlier to integrate with ACS.

    ACS typically includes events or callbacks for things like player hits or kills, which makes it easier to detect when a player kills another. For example, ACS might have an event like OnKill or HumanoidDied that provides details about the killer and victim.

    Key Assumptions:

    • You're using a version of ACS that has an event for kills (e.g., ACS.OnKill or similar). If your ACS module uses a different event name, you'll need to adjust the script accordingly.
    • ACS is properly set up in your game (e.g., as a ModuleScript in ReplicatedStorage or ServerScriptService).
    • Players still have a "leaderstats" folder with a "Coins" IntValue, as in the original script.

    If ACS doesn't have a built-in kill event, we might need to fall back to the original method (e.g., using the Humanoid's Died event and tracking the attacker). Let me know more details about your ACS setup if this doesn't work!

    Updated Script:

    Here's a modified version of the script that integrates with ACS. This script should be placed in ServerScriptService as a server script.

    -- Server Script for awarding 100 coins on player kills using ACS
    -- Place this in ServerScriptService
    
    local Players = game:GetService("Players")
    local ACS = require(game.ReplicatedStorage.ACS)  -- Adjust the path if ACS is located elsewhere (e.g., ServerScriptService)
    
    -- Assuming ACS has an event like "OnKill" that fires with (killerPlayer, victimPlayer) as arguments
    -- If your ACS uses a different event name, replace "OnKill" with the correct one (e.g., "HumanoidDied")
    ACS.OnKill:Connect(function(killerPlayer, victimPlayer)
        if killerPlayer and victimPlayer then  -- Ensure both players exist
            -- Check if the killer is a valid player and has leaderstats
            local killerCharacter = killerPlayer.Character
            if killerCharacter and killerCharacter:FindFirstChild("Humanoid") then  -- Make sure the killer is still alive
                local leaderstats = killerPlayer:FindFirstChild("leaderstats")
                if leaderstats then
                    local coins = leaderstats:FindFirstChild("Coins")  -- Assuming "Coins" is an IntValue
                    if coins then
                        coins.Value = coins.Value + 100  -- Award 100 coins
                        print(killerPlayer.Name .. " has been awarded 100 coins for killing " .. victimPlayer.Name)
                    else
                        warn("Coins value not found in leaderstats for player: " .. killerPlayer.Name)
                    end
                else
                    warn("Leaderstats not found for player: " .. killerPlayer.Name)
                end
            end
        end
    end)
    
    -- Optional: If ACS doesn't handle all cases, you can add a fallback for player joins
    Players.PlayerAdded:Connect(function(player)
        -- This is just in case you need to set up leaderstats here (as in the original script)
        local leaderstats = Instance.new("Folder")
        leaderstats.Name = "leaderstats"
        leaderstats.Parent = player
        
        local coins = Instance.new("IntValue")
        coins.Name = "Coins"
        coins.Value = 0  -- Starting coins
        coins.Parent = leaderstats
    end)
    

    How This Works:

    1. Requiring ACS: The script starts by requiring the ACS module. I assumed it's in game.ReplicatedStorage.ACS, but you might need to change this based on where your ACS ModuleScript is located (e.g., game.ServerScriptService.ACS).

    2. Connecting to ACS Events:

      • The script connects to an ACS event (e.g., ACS.OnKill). This event should fire whenever a player kills another, passing arguments like the killer and victim.
      • Inside the event handler, it checks if the killer and victim are valid, then awards 100 coins to the killer by updating their "Coins" value in leaderstats.
    3. Leaderstats Setup: I included a basic setup for leaderstats in the PlayerAdded event, just like in the original script. This ensures every player has a "Coins" value.

    4. Error Handling: The script includes prints and warnings to help you debug if something goes wrong (e.g., if "Coins" isn't found).

    Potential Issues and Fixes:

    • If ACS Doesn't Have an "OnKill" Event: Some versions of ACS might use a different event name, like ACS.HumanoidDied or ACS.PlayerKilled. Check your ACS documentation or the ModuleScript code to find the exact event. If it's not there, we might need to revert to the original script and manually track attackers.

    • ACS Path Error: If the require line errors out (e.g., "Module not found"), double-check the path to your ACS ModuleScript in Roblox Studio.

    • Testing:

      • Make sure ACS is fully set up in your game and that kills are being detected.
      • Playtest in Roblox Studio: Have two players, make one kill the other, and check if the killer's coins increase.
      • Use the Output window to look for any warnings or errors.

    If this doesn't work as expected, please provide more details about your ACS setup (e.g., the exact event names it uses or how you're handling combat). I can refine the script further! 😊

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.