You can write your topic however you want, but you need to answer these questions:
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.
What is the issue? Include screenshots / videos if possible!
I’m not sure how to script the opposition and call team differential.
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)
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)
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)
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)
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)