#script doesnt detect where the player is properly

1 messages · Page 1 of 1 (latest)

worthy pelican
#

i made this script that assigns values to states of hiding

0 to not hiding
1 to hiding with the door open
2 to hiding with the door closed

problem is the script cant update the values properly

local Players = game:GetService("Players")

script.Parent.Touched:Connect(function(hit)

    local plr = Players:GetPlayerFromCharacter(hit.Parent)
    local char = plr.Character


    if script.Parent.Parent.door.CFrame == script.Parent.Parent.door.open.CFrame and hit.Name == "HumanoidRootPart" then
        char.hidden.Value = 1
    end

    if script.Parent.Parent.door.CFrame == script.Parent.Parent.door.close.CFrame and hit.Name == "HumanoidRootPart" then
        char.hidden.Value = 2
    end
end)

script.Parent.TouchEnded:Connect(function(hit)

    if hit.Name == "HumanoidRootPart" then

local plr = Players:GetPlayerFromCharacter(hit.Parent)

        local char = plr.Character

        char.hidden.Value =  0
end
end)```
vague coyote
#

since you're using touched the event will only fire when the player touches the brick

tender ridge
vague coyote
#

if someone closes the door there's nothing to update the status

tender ridge
#

I would just add in another spatial query to confirm if the player has fully left the cover

vague coyote
#

yeah make a function that uses a spatial query to check player location and also checks if the door is open or closed

#

then link a touched event with a solid debounce and a click detector to that function

tender ridge
vague coyote
#

he hits that little jiggle and then it 'works'

#

btw touchended sucks don't use it

tender ridge
#

Yet to be frank, I would’ve done the same trick that plenty of AAA horror games have used. Just make hiding fully animation based (so you enter via pressing a certain button, not by physically stepping into it)

worthy pelican
#

checking rn

#

i can just make the hiding spot bigger

vague coyote
#

touchended has a lot of unexpected behaviour and ends up firing even when the player is still inside the zone for example in this case

tender ridge
vague coyote
#

is tho because their use case is the player leaving the locker so false positives are issued