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

Why isint my touch event triggering?

Asked by 2 years ago

Hello there ?????. I have a problem triggering the touch event. I am making a parabolic arc using a part (see code:)

local Part1 = script.Parent.Part1

function getXVal(a, b, c, d, Yval)
    return math.asin(Yval/a)*(1/b)
end
wait(1)
print(Part1.Timer.Value)
Part1.Timer.Value = 0
print(math.round(Part1.Position.Y) > 0)
repeat wait()
    Part1.Position = Vector3.new(0,math.abs(30.5*math.sin((math.pi/44)*(5*Part1.Timer.Value+getXVal(30.5, math.pi/44,0,0,8.5)))),5*Part1.Timer.Value)
until math.round(Part1.Position.Y) == 0
Part1.Timer.Value = 0

if you are wondering what Part1 is, its the part I am controlling in this code. Inside the part contains a script and a number value called "Timer" and this is the code (changes the x value as if its in a graph)

while wait() do
    script.Parent.Timer.Value += 0.1
end

I also have a part 2 code:

script.Parent.Touched:Connect(function(hit)
    if hit.Name == "Part1" then
        hit:Destroy()
    end
end)

This code contains the touch event which doesn't seem to be working. If you have any ideas to fix it, please tell me

0
So, first of all, Where is the script located at? There are two locations for the "Timer" value Nicoelyt 4 — 2y
0
The first script is located in the workspace ghostbettert 30 — 2y
0
Also, the Timer value only has one location which is in Part1 ghostbettert 30 — 2y
0
By the way, I don't know if this will be helpful or not but it does'nt detect the part when it touches but it does detect the player when it touches. ghostbettert 30 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

Alright guys, looks like I found out another way to solve my problem. You don't need the touch event. What I did was I kept waiting till Part1's z-coordinate and ordinate passed Part2's z-coordinate and ordinate. Here is the code:

local Part1 = workspace:WaitForChild("Part1")
local debounce = false

while wait() do
    if math.round(Part1.Position.Z) >= math.round(script.Parent.Position.Z) and math.round(Part1.Position.Y) <= math.round(script.Parent.Position.Y) and Part1.Timer.Value > 0 then
        if debounce == false then
            debounce = true
            Part1.Reflect.Value = not Part1.Reflect.Value
            wait(1)
            debounce = false
        end
    end
end
0
If anybody finds another way to solve the problem by using the touch event, please feel free to answer ghostbettert 30 — 2y
Ad

Answer this question