What is the best way that if two parts hit each other (part1,part2) that other one gets destroyed?
aka part1:Destroy()
Thank you for reading!
What is the best way that if two parts hit each other (part1,part2) that other one gets destroyed?
aka part1:Destroy()
Thank you for reading!
You can use the Part.Touched
event.
[part].Touched:Connect(function(p)
if (p == [part2]) then
[part]:Destroy()
end
end
I couldnât get it resolved with RemoteEvent, thank you anyhow i will try to find a alternative until i know a bit more of RemoteEvents.
You could use this, more efficient.
Could you give me a example of how this would be used?
Itâs not a RemoteEvent, itâs built into the part object. No need to add any unnecessary RemoteEvents.
Ah alright, because my model spawns the object and is not yet in the model i use: (WaitforChild)
Because were talking about a âbloxycolaâ that spawns for the player aka a certain fake drink to give the effect off that you get the object.
So the following code looks like this:
local Deletingpart = script.Parent
local model = workspace.The_Lab_Ground_Floor_Objects.VendyMachina.VendingMachine
Deletingpart.Touched:Connect(function(p)
local TweenThisPart1 = model.Fadingobjects:WaitForChild("TweenThisPart")
if (p == TweenThisPart1) then
TweenThisPart1:Destroy()
end
end)
which gets me the following error when a item hits it:
Infinite yield possible on âWorkspace.The_Lab_Ground_Floor_Objects.VendyMachina.VendingMachine.Fadingobjects:WaitForChild(âTweenThisPartâ)â
and the model looks like this
And here is the video how the model work (without ontouch function but i wish to do with it or the drink may stay longer then it must)
Is there any solution to fix the code what i have mention above? and thank you for responding so fast iâm sorry for the late reply.
model.Fadingobjects
doesnât appear to have an object called âTweenThisPartâ in it.
Oh my bad i forgot to give you the local script of the vending machine itself (it starts in the player)
In the script on where it said local function dropObject() the object would be created reason why i used waitforchild for this reason. Still sadly enough i have to delete the part after a wait which i try to prevent with the code you gave me which gave me the error:
Infinite yield possible on âWorkspace.The_Lab_Ground_Floor_Objects.VendyMachina.VendingMachine.Fadingobjects:WaitForChild(âTweenThisPartâ)â
anyhow Thank you for reading and i see your reply shortly!
local TweenService = game:GetService("TweenService")
local Player = game.Players.LocalPlayer
local model = workspace.The_Lab_Ground_Floor_Objects.VendyMachina.VendingMachine
local Keypadandscreen = model.Keypadandscreen
local N1 = Keypadandscreen.N1
local Coinhole = model.Keypaddetail.Coinhole
local PriceShowing = Keypadandscreen.Model.PriceScreen.SurfaceGui.TextLabel
local FakeDrinkDrop = model.FakeDrinks.Drinkthatbeduplicated
local Character = script.Parent
local RemoteEvents = model.RemoteEvents
local debounce = false ---- setting the cooldown ready
local Removefakeitem = model.Bordercase.Deletingthefakeitem
local Crits = Player.leaderstats.Crits.Value
ClickDetector = Instance.new("ClickDetector")
local CursorId = "2287179355"
ClickDetector.Parent = N1
ClickDetector.MaxActivationDistance = 10
local GiveCoin = model.Case.Coin
local function dropObject()
local Dropdrink = FakeDrinkDrop:Clone()
Dropdrink.Position = FakeDrinkDrop.Position spawnlocation at the dropper position.
Dropdrink.Parent = model.Fadingobjects ---- making it so that the parts of getting in the object folder
Dropdrink.Name = "TweenThisPart"
FakeDrinkDrop.Transparency = 1
end
ClickDetector2buy = Instance.new("ClickDetector")
local CursorId = "2287179355"
ClickDetector2buy.Parent = Coinhole
ClickDetector2buy.MaxActivationDistance = 10
ClickDetector2buy.MouseClick:Connect(function()
local NumberValueVendingMachine = Character.VendingMachineScript.NumberValueVendingMachine
if NumberValueVendingMachine.Value == 1 and debounce == false then
debounce = true
NumberValueVendingMachine.Value = NumberValueVendingMachine.Value - 1
GiveCoin.Transparency = 0
CoinTweenforward:play()
wait(2)
GiveCoin.Transparency = 1
PriceShowing.Text = ("We recieved your money, your drink shall be with you soon.")
wait(2)
dropObject()
local TweenThisPart = model.Fadingobjects.TweenThisPart
TweenThisPart.Transparency = 0
local tween1 = TweenService:Create(TweenThisPart, tweeningInformation, {Position = Vector3.new(-49.651, 7.951, -82.4)}) -----
tween1:play()
wait(2)
CoinTweenbackward:play()
TweenThisPart.Anchored = false
FakeDrinkDrop.Transparency = 0
RemoteEvents.BuyBloxyCola:FireServer(Player,"BloxySoda")
wait(1)
PriceShowing.Text = ("Enjoy your drink!")
TweenThisPart:Destroy()
debounce = false
elseif NumberValueVendingMachine.Value == 1 and Crits < 1 and debounce == false then
local NumberValueVendingMachine = Character.VendingMachineScript.NumberValueVendingMachine
debounce = true
NumberValueVendingMachine.Value = NumberValueVendingMachine.Value - 1
PriceShowing.Text = ("You have not enough Crits to buy this product.")
debounce = false
end
end)