#Checking at player if they are currently touching a part...

39 messages · Page 1 of 1 (latest)

sullen elbow
#

TouchEvent?

vital oriole
#

But how would I implement it into this function? I've done regular before but never embedded into another function

vital oriole
#

Use the part.Touched:Connect(function()

#

@vital oriole

vital oriole
#

part.Touched:Connect(function()
print("part touched")
end)

#

If I understood ur trying to get the script to run like this : Player Touches the part> Script Prints That The Blocks Has Been Touched> If the block isn't being touched by any player it prints that it hasn't been touched

#

local foobar = workspace.ejector

foorbar.Touched:Connect(function()
print("text here")
end)

sullen elbow
#

Just mess with the TouchEvent or get a tutorial about it

#

There's also TouchEnded

vital oriole
#

Yea

delicate grottoBOT
#

studio** You are now Level 5! **studio

vital oriole
#

no, so like if I press button A, then it will run like the:

local button = script.Parent
local foobar = workplace.ejector
function wafflehouse()
  for _, player in pairs(game.Players:GetPlayers()) do
     if player is touching foobar then
          print("Yea... your standing on it")
          --launch player 100studs in air if they are standing on the part at that moment
     else
          print("Not even close")
          --Does not launch the players not touching the part at that moment
     end
  end
end

button.Touched:Connect(function(waffleHouse))
delicate grottoBOT
#

studio** You are now Level 2! **studio

sullen elbow
#

Press a keyboard key?

#

That requires UserInputService

vital oriole
#

U mean if the player is standing on the block and presses the button a launches them 100 studs above?

#

no, like if any player touches the button (like the button is 200 studs away from the "foobar", if anyone is on it when said player presses the button, it launches them

#

The button is a part in the workspace or a ui

#

workspace

#

Use touch event and And body velocity

#

Calculate the distance between the character and the button

#

@vital oriole

#
local button = script.Parent
local foobar = workspace.ejector

function launchPlayers()
    for _, player in pairs(game.Players:GetPlayers()) do
        local character = player.Character
        if character then
            local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")

            if humanoidRootPart and humanoidRootPart:IsA("BasePart") then
                local distance = (foobar.Position - humanoidRootPart.Position).Magnitude

                if distance >= 200 then
                    print("Launching player " .. player.Name)
                    humanoidRootPart.Velocity = Vector3.new(0, 100, 0)  -- Adjust the launch velocity as needed
                else
                    print(player.Name .. " is not far enough")
                end
            end
        end
    end
end

button.Touched:Connect(launchPlayers)
#

Tell me if it works

#

This isnt what im looking for

#

hang on

#

I rewrote the code

#

If u mean that the foobar has to be touched

#

Then replace button.Touched with foobar

#

Might have mistaken that

#

no, what im looking for was like this for the checking each player to test

for _, player in pairs(game.Players:GetPlayers()) do
  if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
     local rootPart = player.Character.HumanoidRootPart
     local touchingFoobar = rootPart:IsA("BasePart") and rootPart.Name == "EjectorPad"
     if touchingFoobar then
    functionToEject(player)
     end
  end
end
#

Why do you need to check if some of the player is touching the part with ipairs

#

When u can use touchedevent

#

Look up a tutorial on touch events

#

people moving causes it to spam them on & off the pad if they are running on the pad

#

U can disable the pad for certain players

#

For tot seconds

#

Store them in a table