Hello-
I've created a tool that basically just changes a players team if they are clicked on. The problem is that this tool only works part of the time. The tool usually works the very first time the character spawns but after that, nothing happens and no errors appear.
Here's the basic script:
MouseHold = false
local Tool = script.Parent
local User
Tool.Equipped:connect(function(mouse)
mouse.Icon = "http://www.roblox.com/asset/?id=57571495"
User = Tool.Parent
if User.Humanoid.Health <= 0 then
script.Parent:Remove()
end
mouse.Button1Down:connect(function()
local Ray = Ray.new(Tool.Handle.CFrame.p,(mouse.Hit.p - Tool.Handle.CFrame.p).unit * 999)
local Hit,Position = game.Workspace:FindPartOnRay(Ray,User)
if Hit then
local Character = Hit.Parent
if Hit.Parent:FindFirstChild("GroupRank") then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
local Mag = (User.Torso.Position - Hit.Parent.Torso.Position).magnitude
if Mag < 20 then
local PlayersFirstTeam = Player.TeamColor
Player.TeamColor = BrickColor.new("Bright orange")
print("Moving on")
wait(20)
Player.TeamColor = PlayersFirstTeam
end
end
end
end)
end)
As always, help is appreciated, Thanks!

1 comment
What's the variable "User" for?