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

Confused on how to operate this script?

Asked by 9 years ago
local Part = script.Parent --Part to get touched
local Tool = ????? --The tool you want to give them
local TeamColor = "BrightBlue" --Team color here

Part.Touched:connect(function(hit)
    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if Player and Player.TeamColor == BrickColor.new(TeamColor) then
        Tool:Clone().Parent = Player.Backpack
        Tool:Clone().Parent = Player.StarterGear
    end
end)

Where do I put the tool for it to give it to someone on the same team as the giver is set to? The tool i am trying to give is OCA Nano. Thanks!

1 answer

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
9 years ago

First of all, you set the TeamColor to 'BrightBlue' which is not a valid BrickColor, 'Bright blue' however is. Secondly, you would put the location of the tool with the variable Tool.

Here is what the first 3 lines should look like:

local Part = script.Parent -- location of Part
local Tool = [Location of Tool] -- An example would be 'game.ReplicatedStorage.Tool'
local TeamColor = "Bright blue" -- Lua is case sensitive and spaces matter!

Fix (using debounce):

local Part = script.Parent -- location of Part
local Tool = [Location of Tool]
local TeamColor = "Bright blue"

local debounce = false

Part.Touched:connect(function(hit)
    if debounce == false then
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if Player and Player.TeamColor == BrickColor.new(TeamColor) then
                Tool:Clone().Parent = Player.Backpack
                Tool:Clone().Parent = Player.StarterGear
            end
        wait(1) -- Wait time until it gives tool again
        debounce = true
    end
end)


0
Thanks this worked! MULTACxlr8 20 — 9y
0
Actually how do i fix this? When i touch it it rapidly gives me the tool can i set it to wait like 10 seconds before it gives another? I tried using wait(100) but then the script doesn't work? MULTACxlr8 20 — 9y
0
Check the edit BlackJPI 2658 — 9y
Ad

Answer this question