Ok so I just recently got into scripting and decided to try and make a tycoon game to challenge myself. There is 2 things I need help with now. So the first is when a part falls from the dropper on to the conveyor belt then hits the part at the end of the conveyor belt which would add money to the player. How would I make a script that gets destroyed once it hits the part at the end of the conveyor and gives money to the player.
My second question is how would I make it so that when a player CLICKS to buy a dropper they get money removed if they have enough money and the dropper starts working after that.
Use a Touched
event, these are fired whenever any physical objects touch with any part that the variable part
is set to
The part
variable is optional but there for the sake of easier readability
The hit
inside of the function(hit)
is the parameter, it basically gets what part touched us, you can read more about it on the dev hub here
The if hit.Name == "moneybrick" then
line checks for the name of the brick that touched us, if the bricks name does not match the string it will not execute anything inside of this if
statement
:Destroy()
is a function of everything, removes its existence from the game (never tested it on services before, so idek if it can can destroy services lol)
local part = script.Parent part.Touched:Connect(function(hit) if hit.Name == "moneybrick" then -- change the string value to the name of the money brick from the dropper hit:Destroy() end end)
Just simply put a normal Script inside the part you're trying to affect and paste this code:
script.Parent.Touched:Connect(function() script.Parent:Destroy() end)
Put this script in the part destroyer part.
function onTouch(part) local yeet = part.Parent:FindFirstChild("PartName") --Change PartName to the name of the part that will be destroyed. Make sure the part that is going to be destroyed is in Workspace. If not change part.Parent to Part.Parent.GroupName if (yeet ~= nil) then -- if the part that will be destroyed exists, then yeet:Destroy() end end script.Parent.Touched:connect(onTouch)