How do I make it so a tool is placed when it's come into contact with a model?

Hi!

For example, lets say I have a tool called ‘Burger Buns w/ Meat’ in my inventory, and I hold the tool and go up to a grill and make the tool touch the grill, how do I make it so when the tool touches the grill that the tool will stay on top of the grill for a certain amount of time and then return to my inventory as ‘Cooked Burger’?

2 Likes

A server script would have to handle this unless you want this only to be seen by the local player but when .Touched is fired, here’s one option:

  1. Copy the CFrame of the burger main part
  2. Destroy the tool
  3. Have a model with PrimaryPart set to the part we copied the CFrame of
  4. Model:SetPrimaryPartCFrame() to the CFrame we saved
  5. wait…
  6. Give cooked burger tool to player

I’m a beginner scripter so I’m not sure what anything you just said means, it’s probably simple, would it be okay to break it down?

This is probably the dumbest way to break it down:

  1. Upon touch of the grill with the “Burger Buns w/Meat” tool equipped, the tool will be destroyed (Or just parented to nil) and a prop will replace the Tool so that it looks like it’s cooking

  2. Wait for a couple of seconds, then give the cooked burger the Player

The way how we could do this, is by using a Touched event inside the Grill Part, which pretty much detects when a part gets touched by another part physics-wise

Say we insert a script for our tool we want to cook:

local TouchOnce = false
local Tool = script.Parent
local Handle = Tool.Handle

Handle.Touched:Connect(function(Hit)

end)

The TouchOnce variable will only fire once using a conditional check, the Handle is what we want to use the Touched event on (Or the grill, doesn’t really matter) & we’re setting our Event

Next, we’ll add this inside our event:

Handle.Touched:Connect(function(Hit)
    local Character = Tool.Parent
    local Player = game.Players:GetPlayerFromCharacter(Character)
    if Player and Hit.Name == "Grill" and TouchOnce == false then
        TouchOnce = true
        Tool = nil
        wait(5)
        local CookedBurger = game.ServerStorage.CookedBurger:Clone()
        CookedBurger.Parent = Player.Backpack
        Tool:Destroy()
    end
end)

Now you may think: “THIS IS A LOT OF STUFF” and you’re kinda right but let’s break this down here :sweat_smile:

    local Character = Tool.Parent
    local Player = game.Players:GetPlayerFromCharacter(Character)

These lines are basically just getting our Player that touched the Grill with the burger, so we can save it later on in their backpack

    if Player and Hit.Name == "Grill" and TouchOnce == false then

Next, we’re implementing 3 conditional checks: 1 if the Player is valid, 1 if the Part that we hit is a “Grill” part, and that our TouchOnce is set to false so we can set it to true from preventing any overlapping events fired

       TouchOnce = true
       Tool = nil
       local PropTool = game.ServerStorage.GrillBurger:Clone()
       PropTool.Parent = workspace.Grill.Position + Vector3.new(0, 5, 0)
       wait(5)
       PropTool:Destroy()
       local CookedBurger = game.ServerStorage.CookedBurger:Clone()
       CookedBurger.Parent = Player.Backpack
       Tool:Destroy()

We’re setting our TouchOnce to true, now we’re actually setting our Tool variable to nil cause we want to still save the script that’s inside the Tool

Next we’re creating a prop burger for the grill to cook, then setting its position correcrtly

Then after 5 seconds, we can give the Cooked Burger to the Player and destroy our old tool cause we don’t need it anymore!

Thank you so much! This was very detailed and I’ll try it out now, thanks!

Is it okay if you could fill me in on where to put all these scripts? Or are they all in the same script? If so, where do I put it? Also, would this mean I need to create a Cooked Burger tool and put it in ReplicatedStorage [where i store all my game tools] so that when the prop tool is done cooking the Cooked Burger tool in ReplicatedStorage will go in my inventory? Lastly, where do I put the prop tool that will be on the grill? Sorry if it’s too much to ask, I’m a beginner scripter so I don’t understand alot of this stuff.

The Forum died for the 500th time good job

That’s just the entire script, that’s parented inside the Tool object

Preferably ServerStorage, but yes you could just make the burger more dark colored and place it inside there

You could just call this:

       local PropTool = game.ServerStorage.GrillBurger:Clone()
       PropTool.Parent = workspace
       PropTool.Position = workspace.Grill.Position + Vector3.new(0, 5, 0)

This will set the PropTool’s position to where the grill is, and moving it upwards so that it’s on the grill (AND NOT INSIDE CAUSE THAT WOULD LOOK WEIRD)

Ahh, I probably sound so dumb right now, but what do you mean by Tool object? Like the ‘Burger w/ Meat’? Or the PropTool inside ReplicatedStorage?

Yeah, or basically the Tool you want to cook when you touch the grill

Okay! Thanks, I’ll keep you updated on how it goes.

1 Like

I’m so sorry to ask, I’m not even sure if I’m allowed to ask this on the DevForum, but could you do it for me? I’m genuinley so stuck on something so simple and I can’t really understand it. It’s okay if you don’t have time or dont want to.

The thing is, that’s isn’t really allowed

The start of creating a topic suggests not for people to write an entire script for you, we’re only there to help you with your issue (I gave a good example on how you could)