Hey! I made a weld script that attachs a part to a certain team. The problem is it only attaches if I either reset or load the character, I don’t want to do that. How do I make it work instantly as I get set to a team?
Heres the script:
local killerteam = game:GetService("Teams")["Killer"]
game.PlayerAdded:Connect(function(play)
play.CharacterAdded:Connect(function(player)
if play.TeamColor == killerteam.TeamColor then
local character = play.Character or play.CharacterAdded:Wait()
local kb = game.ReplicatedStorage.KillBrick:Clone()
kb.Parent = character
local weld = Instance.new("WeldConstraint")
weld.Parent = character
weld.Part0 = kb
weld.Part1 = character.Head
kb.CFrame = (character.Head.CFrame + Vector3.new(0,0,2))
kb.Orientation = Vector3.new (-90,0,0)
kb.IsInUse.Value = true
end
end)
end)
--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")
--//Variables
local KillBrick = ReplicatedStorage.KillBrick
local KillerTeam = Teams.Killer
--//Tables
local Connections = {}
--//Functions
Players.PlayerAdded:Connect(function(player)
player:GetPropertyChangedSignal("Team"):Connect(function()
if player.Team == KillerTeam then
local character = player.Character
if character then
local killBrick = KillBrick:Clone()
killBrick.IsInUse.Value = true
killBrick.Parent = character
local weld = Instance.new("WeldConstraint")
weld.Part0 = killBrick
weld.Part1 = character.Head
weld.Parent = character
killBrick.CFrame = character.Head.CFrame + Vector3.new(0, 0, 2)
killBrick.Orientation = Vector3.new(-90, 0, 0)
end
Connections[player] = player.CharacterAdded:Connect(function(character)
local killBrick = KillBrick:Clone()
killBrick.IsInUse.Value = true
killBrick.Parent = character
local weld = Instance.new("WeldConstraint")
weld.Part0 = killBrick
weld.Part1 = character.Head
weld.Parent = character
killBrick.CFrame = character.Head.CFrame + Vector3.new(0, 0, 2)
killBrick.Orientation = Vector3.new(-90, 0, 0)
end)
else
local connection = Connections[player]
if connection then
connection:Disconnect()
end
--//Reset the character back to normal here
end
end)
end)
The script works but when you rotate, you pivote around your center of mass which is really far because the block is really far away and it causes you to fling. this didnt happen to the original script so I don’t know what causes it
Does this work? (I just used your old code for setting the part and welds):
--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")
--//Variables
local KillBrick = ReplicatedStorage.KillBrick
local KillerTeam = Teams.Killer
--//Tables
local Connections = {}
--//Functions
Players.PlayerAdded:Connect(function(player)
player:GetPropertyChangedSignal("Team"):Connect(function()
if player.Team == KillerTeam then
local character = player.Character
if character then
local kb = KillBrick:Clone()
kb.Parent = character
local weld = Instance.new("WeldConstraint")
weld.Parent = character
weld.Part0 = kb
weld.Part1 = character.Head
kb.CFrame = (character.Head.CFrame + Vector3.new(0,0,2))
kb.Orientation = Vector3.new (-90,0,0)
kb.IsInUse.Value = true
end
Connections[player] = player.CharacterAdded:Connect(function(character)
local kb = KillBrick:Clone()
kb.Parent = character
local weld = Instance.new("WeldConstraint")
weld.Parent = character
weld.Part0 = kb
weld.Part1 = character.Head
kb.CFrame = (character.Head.CFrame + Vector3.new(0,0,2))
kb.Orientation = Vector3.new (-90,0,0)
kb.IsInUse.Value = true
end)
else
local connection = Connections[player]
if connection then
connection:Disconnect()
end
--//Reset the character back to normal here
end
end)
end)
nevermind i got it working perfectly after i made a little change. in the script i had been welding it before i moved it to the player which is what caused the insane offset