Team versus Team Tool

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to turn my script that allows people to sit other people with a tool to only sit players on an opposite team.

  2. What is the issue? Include screenshots / videos if possible!
    I’m not sure how to script the opposition and call team differential.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried ChatGPT, but the script is not working.

Here is my normal script

function sitDown(hit)
	h = hit.Parent:findFirstChild("Humanoid")
	if (h ~= nil) then
		h.Sit = true
		wait(1)
		h.Sit = false
	end
end

script.Parent.Touched:connect(sitDown)

You can use Players:GetPlayerFromCharacter to get the hit player, and you can access the Team property to check if they’re on different teams.

Do you how plug this into my script? I’m not sure where to start.

I tried this,

function sitDown(hit)
	local h = hit.Parent:findFirstChild("Humanoid")
	if h then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local touchingPlayer = game.Players:GetPlayerFromCharacter(script.Parent.Parent)

		if player and touchingPlayer and player.Team ~= touchingPlayer.Team then
			h.Sit = true
			wait(1)
			h.Sit = false
		end
	end
end

script.Parent.Touched:connect(sitDown)

However, I’m still sitting down everyone.

1 Like

Could we get more context? This seems like too little to go off.

What’s the function for? What type of script is this? Is this script located inside of a school?

Maybe send an explorer screen shot or something because I’m very confused.

1 Like

Try this and let me know what gets printed:

local Players = game:GetService("Players")

local LocalPlayer = Players.LocalPlayer

local function sitDown(hit)
	local otherPlayer = Players:GetPlayerFromCharacter(hit.Parent)
	if otherPlayer then
		print(LocalPlayer.Team, otherPlayer.Team, otherPlayer.Team ~= LocalPlayer.Team)
		if otherPlayer.Team ~= LocalPlayer.Team then
			otherPlayer.Sit = true
			task.wait(1)
			otherPlayer.Sit = false
		end
	end
end

script.Parent.Touched:Connect(sitDown)
1 Like

It’s located inside a tool, its a normal script, and the function is to sit a player that gets touched by the tool.

1 Like

This isn’t working for some reason. It won’t sit anybody.

1 Like

Try this:

function sitDown(hit)

	h = hit.Parent:FindFirstChild("Humanoid")

 	if h ~= nil then
        local plr = game.Players:FindFirstChild(hit.Parent.Name)
        local plrteam = plr.Team

        local gearowner = game.Players:FindFirstChild(script.Parent.Parent.Name)
        local ownerteam = gearowner.Team

        if plrteam ~= ownerteam then
            h.Sit = true
	    	task.wait(1)
	     	h.Sit = false
       end
    
	end

end

script.Parent.Touched:Connect(sitDown)

Nope.

I think I found the problem. You forgot to define one of the variables as “local.” Try this out and keep asking me if you have any more problems.

function sitDown(hit)

	local h = hit.Parent:FindFirstChild("Humanoid")

 	if h ~= nil then
        local plr = game.Players:FindFirstChild(hit.Parent.Name)
        local plrteam = plr.Team

        local gearowner = game.Players:FindFirstChild(script.Parent.Parent.Name)
        local ownerteam = gearowner.Team

        if plrteam ~= ownerteam then
            h.Sit = true
	    	task.wait(1)
	     	h.Sit = false
       end
    
	end

end

script.Parent.Touched:Connect(sitDown)

i recommend watching a beginners tutorial for scripting