Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Confused on how to operate this script?

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

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)


3 comments

0

Thanks this worked!

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?

0

Check the edit

This discussion is preserved as it was. New answers, comments, and votes are closed.