I am writing a script for a game where I want players to earn money for stepping on a brick, but for only one team. Please help me
Simple, add an if statement for the team color. For example...
game.Workspace.Part.Touched:connect(function(Hit) if hit.Parent:FindFirstChild("Humanoid") then if game.Players:GetPlayerFromCharacter(Hit.Parent ) ~= nil then if game.Players:GetPlayerFromCharacter(Hit.Parent).TeamColor == "Really Blue" then --Code end end end end)
game.Workspace.Part.Touched:connect(function(Hit)
if hit.Parent:FindFirstChild("Humanoid") then if game.Players:GetPlayerFromCharacter(Hit.Parent ) ~= nil then if game.Players:GetPlayerFromCharacter(Hit.Parent).TeamColor == "Lime green" then
moneyToGive = 100 debounce = false script.Parent.Touched:connect(function(hit) if debounce == true then return end player = game.Players:GetPlayerFromCharacter(hit.Parent) if player == nil then return end stat = player:findFirstChild("leaderstats") if stat == nil then return end cash = stat:findFirstChild("Cash") if cash == nil and then return end debounce = true cash.Value = cash.Value + moneyToGive wait(2) debounce = false end)
end end end
end)
animorphs30 had the right idea.
I've touched up your script, but the only real modifications are:
specialTeam
.Team
is different than specialTeam
.local moneyToGive = 100 local debounce = false local specialTeam = game.Teams["Special Team"] --change the part in quotations to match the name of the desired team script.Parent.Touched:connect(function(hit) if debounce then return end local player = game.Players:GetPlayerFromCharacter(hit.Parent) if not player or player.Team ~= specialTeam then return end local stat = player:FindFirstChild("leaderstats") if not stat then return end local cash = stat:FindFirstChild("Cash") if not cash then return end debounce = true cash.Value = cash.Value + moneyToGive wait(2) debounce = false end)