Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I detect for these two things in my codes?

Asked by
Cyrexal -12
4 years ago

Hey I've been trying to recreate this hat system from King of the Hat and I'm 2 steps away from getting it almost fully working and I was just wondering how can I do detection stuff because I seem to be struggling with that. (not sure if that's the right term, but yeah lol)

So here is my code for picking up the hat, but I wanna make so if the players right or left leg touches it then do the code because I don't want the arms or head or hat to interfere with it (ex: when a player walks up to the opponent they'll both just die first the opponent and then the player because the opponents hat or head touched theirs as it fell)

    --Picking Up The Hat        
    ClonedHat.Touched:Connect(function(hit)

      if hit:IsDescendantOf(character) then
        if hit == character:FindFirstChild("Right Leg") or hit == character:FindFirstChild("Left Leg") then
        weld.Parent = ClonedHat --Weld the hat back to their head

      else --The player touching the hat doesn't own it so it's the opponent
        local opponent = Players:GetPlayerFromCharacter(hit.Parent)

        if opponent then
          character:BreakJoints() --Kill the player that owns the hat
          opponent.leaderstats.Points.Value = opponent.leaderstats.Points.Value + 1 --Give the opponent 1 point
          end
        end
      end
    end)

    ClonedHat.Parent = character
            end
        end)

I also have this code for throwing the hat and I need to figure out if the hat touches a player while it's flying in the air remove the opponents hat and knock em back a bit

--Throwing The Hat
Throw.OnServerEvent:Connect(function(player,cframe)
  local character = player.Character
  local Hat = character:FindFirstChild('Hat')
  local weld = Hat:FindFirstChild('Weld')

  if weld then
    weld.Parent = nil

    --Moves The Hat Forward
    local bodyVelocity = Instance.new("BodyVelocity")
    bodyVelocity.MaxForce = Vector3.new(500,500,500)
    bodyVelocity.Velocity = (character.HumanoidRootPart.CFrame.lookVector*25)
    --bodyVelocity.Velocity = cframe.p --this is so the hat will be thrown to where the mouse is located but then the speed of the throw goes wack
    bodyVelocity.Parent = character:FindFirstChild('Hat')

    --Destroy the bodyVelocity to stop it from moving after 5 seconds
    wait(5)
    bodyVelocity:Destroy()
    end
end)

I've been messing around for a few days now, but just can't seem to make much progress p.s: sorry if the title is bad it took me 5 tries to get one that would work lol

Answer this question