Ad
Log in to vote
1

Any alternatives to touchended?

Asked by 4 days ago

I've recently been making a custom tool pick up script, however, I've noticed that touch ended can be very buggy in which it can activate even when the player is still inside the part. The player is supposed to pick up the object when pressing "e" however if the player were to walk across the part, if the script does not have touchended, the player would still be able to pick up the object after walking pass it with the press of "e". Thus, I needed a touchended to create a variable to stop this from happening. Though it does solve the previous problem, it created a new one in which touchended would fire even when the player is still touching the object, continuously activating my touch ended variable and breaking my script. Can anyone help with this?

equipped = false
--Remote event that fires when touched
Prompt.onClientEvent:connect(function(player)
HasTouched = true
end

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
-- check if E is pressed
        if inputObject.KeyCode == Enum.KeyCode.E then
            if not Equipped and HasTouched then
                equipped = true
                HasTouched = false
            elseif Equipped  then
                equipped = false
                HasTouched = true
end
end
end)

--Buggy Part that causes HasTouched to be false, thus not entering into both of the ifs above
--Remote event that fires when touchended

Prompt2.onClientEvent:connect(function()
    HasTouched = false
    print("Touched Ended")  
end)

1
0
Could you give me an example? The wiki can really complicated sometimes. AbandonedRick 45 — 4d
0
Whoops, Part:GetTouchingParts() could be used, though it wouldnt be the most efficient thing you could do. NexanianStudios 46 — 4d
0
Thanks for your help guys! Vulkarin's answer works. AbandonedRick 45 — 4d
View all comments (2 more)
0
Region3s are also very helpful, they allow for a more precise detection mattscy 51 — 4d
0
Sorry I would have given an example but I was in bed when you wrote that Vulkarin 17 — 3d

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

Answer this question



Ad