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

Any alternatives to touchended? [Solved] [closed]

Asked by 7 years ago
Edited by OldPalHappy 7 years 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?

01equipped = false
02--Remote event that fires when touched
03Prompt.onClientEvent:connect(function(player)
04HasTouched = true
05end
06 
07game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
08-- check if E is pressed
09        if inputObject.KeyCode == Enum.KeyCode.E then
10            if not Equipped and HasTouched then
11                equipped = true
12                HasTouched = false
13            elseif Equipped  then
14                equipped = false
15                HasTouched = true
View all 26 lines...
2
You could try magnitude http://wiki.roblox.com/index.php?title=Magnitude Vulkarin 581 — 7y
0
Could you give me an example? The wiki can really be complicated sometimes. AbandonedRick 112 — 7y
0
Whoops, Part:GetTouchingParts() could be used, though it wouldnt be the most efficient thing you could do. NexanianStudios 91 — 7y
0
Thanks for your help guys! Vulkarin's answer works. AbandonedRick 112 — 7y
0
Region3s are also very helpful, they allow for a more precise detection mattscy 3725 — 7y

Locked by cabbler, Vulkarin, Operation_Meme, and MessorAdmin

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?