#Touched Pressure plate
1 messages · Page 1 of 1 (latest)
local model = game.Workspace:FindFirstChild("PressurePlateDoor")
local pressurePlate = model.PressurePlate.PressurePlate
local door = model.Door.Door
local direction = Vector3.new(3, 2, 3)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {script.Parent}
while task.wait(0.2) do
local result = workspace:Raycast(pressurePlate.Position, direction, params)
if result then
local hitPart = result.Instance
local character = hitPart:FindFirstAncestorOfClass("Model")
if character and character:FindFirstChild("Humanoid") then
print("Player detected:", character.Name)
end
end
end
i dont understand
Why raycast and not .Touched?
i tried to change the direction of the raycast, by adding 3
tried it once with touched
and its worse
Touched is just bad
some guy told me to never use it
so i dont
very wise guy
this doesnt seem to do much
pls help
I dont know much about raycasts but try to do Vector3.new(0,-1,0)
thats under the pressure plate no ?
idk
at first it was 0 2 0
then i experimented some things
but its useless it doesnt work
changed it back to 0 2 0
Try to do 0,0.1,0
nvm, imma still try it with Touched
see if they changed it or if i still have the same bugs
local model = game.Workspace:FindFirstChild("PressurePlateDoor")
local pressurePlate = model.PressurePlate.PressurePlate
local door = model.Door.Door
pressurePlate.Touched:Connect(function(hitPart)
local character = hitPart.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
print("human")
end
end)
now it works fine
but
it only detects the player for like 1 second
then it stops
and when i move on the pressure plate
it works again
then it stops after a moment
lemme video this
Touched Pressure plate
ok nvm
i fixed it
with Touched
and a lot of code
local model = game.Workspace:FindFirstChild("PressurePlateDoor")
local pressurePlate = model.PressurePlate.PressurePlate
local door = model.Door.Door
local playersOnPlate = {}
pressurePlate.Touched:Connect(function(hitPart)
local character = hitPart.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
local playerName = character.Name
if not playersOnPlate[playerName] then
playersOnPlate[playerName] = true
print("Player on:")
door.Transparency = 0.5
door.CanCollide = false
end
end
end)
pressurePlate.TouchEnded:Connect(function(hitPart)
local character = hitPart.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
local playerName = character.Name
task.delay(0.5, function()
if playersOnPlate[playerName] then
local touching = false
for _, part in ipairs(pressurePlate:GetTouchingParts()) do
local char = part.Parent
local hum = char and char:FindFirstChild("Humanoid")
if hum and char.Name == playerName then
touching = true
break
end
end
if not touching then
playersOnPlate[playerName] = nil
print("Player left:")
if next(playersOnPlate) == nil then
door.Transparency = 0
door.CanCollide = true
end
end
end
end)
end
end)
final code if anyone wondering
i would use this if i were u to detect the player the player stepping on the pressure plate
local model = workspace:FindFirstChild("PressurePlateDoor")
local pressurePlate = model.PressurePlate.PressurePlate
local rs = game:GetService("RunService")
local players = game:GetService("Players")
local playersOn = {}
players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
for _, bodyPart in char:GetDescendants() do
if bodyPart:IsA("Part") then
rs.Heartbeat:Connect(function()
if (bodyPart.Position - pressurePlate.Position).Magnitude < 1 then
if not table.find(playersOn, plr) then
table.insert(playersOn, plr)
print(plr.Name .. " is on the pressure plate!")
end
else
if table.find(playersOn, plr) then
table.remove(playersOn, table.find(playersOn, plr))
end
end
end)
end
end
end)
end)
There is a lot to say...