This is most like a noob mistake so i will allow you all to laugh at me on this one.
i mustnt understand the hit parameter properly as im using one through a remote event to destroy something
i did this already for another function and that one works well
however, in this function it thinks the payer is touching the part when the animation plays which results in everything getting deleted…
here is the function in question
local function destroyBox(hit)
local PointsCrate = game.Workspace["Level 1"].PointsCrate
PointsCrate = hit.Parent
if hit.Parent then
print("touched")
else
print ("not touched")
end
if SlideTrack.IsPlaying then
print("isplaying")
else
print("not playing")
end
end
foot.Touched:Connect(destroyBox)
so the first if statement plays out correctly, it prints “touched” when touching the part
but when isPlaying is checked in the second if statement (when i play the animation) it prints “touched” even when im not touching the part.
im not sure if i have used it wrong since there is another function withthe hit parameter in the same script or if i just havent set the variable correctly, thoughts?
ok lemme try again.
i have a box im trying to destroy when i slide into it
i stripped my code down to check for the issue
the issue is when i slide, it thinks im touching the box when im not
this made it so when the remote event fired, it deleted everything else
i dont fully understand what you mean since the hit.Parent is the PointsCrate not the Player.
i’ve done exact same thing in another function that kills an NPC that is why im confused.
so to repeat myself here,
i rearranged my code to do seperate checks to find the problem
the first check is to see if i touch the part or not, works as intended only prints when i touch the PointsCrate
the second check is to check whether the anim plays since i have to slide to break it
it is here where it thinks every part is the PointsCrate when i do the animation.
local function destroyBox(hit)
local PointsCrate = game.Workspace["Level 1"].PointsCrate
if hit or hit.Parent == PointsCrate then
print("touched")
else
print ("not touched")
end
if SlideTrack.IsPlaying then
print("isplaying")
else
print("not playing")
end
end
foot.Touched:Connect(destroyBox)
This means that you want to remove the frame when the player “slides” into a certain part and for this to happen via a remote event
It would have to work on this principle, if this is not what you mean, try to show some visualization of what you have in mind
LocalPlayer
local RS = game:GetService("ReplicatedStorage")
local slidepart = workspace.SlidePart
local RSlide = RS.Slide
slidepart.Touched:Connect(function(destorybox)
if destorybox.Parent:FindFirstChild("Humanoid") then
RSlide:FireServer()
end
end)
Server
local RS = game:GetService("ReplicatedStorage")
local boxToDestroy = workspace.DestroyBox
local RSlide = RS.Slide
RSlide.OnServerEvent:Connect(function(destroyBox)
boxToDestroy:Destroy()
end)
What @gIwwinnq is saying is that your crate is being touched by something else. Your current code is not checking if the player is touching the part, but rather if any part touching the box has a parent and if it does, it will get destroyed. You need to implement a check to see if this part touching the box has a humanoid.
I’m confused what you are trying to convey to us? Could you explain if the “is playing” being repeated multiple times or not? Besides, the slide should be outside of the function once it has been called off since the case is being duplicated many times when touching with hit, may I ask to know what is “foot” assigned to?
Also when the slide track is playing, it may have been due to another base part touching it. That is where you could implement a check there if it is the foot is touching it and also the slide track is playing.
if its being touched by something else then why does the first if statement only print when the player touches the box and not be touched multiple times by the part its on top of?
its when the second if statement comes into play, as soon as the player slides it will print “touched” when u slide on any part. “isPlaying” will only print when the animation plays as intended.
when i slide it thinks everything is the box so if i added the remote event back in it would delete everything else no matter where i was sliding
ok im guess i have to show you since words aint doing much for me
if i connect my remote event back to the function, this happens: robloxapp-20240201-2325120.wmv (872.6 KB)
as i have been saying it thinks everything is the box