Touch Detection

Hello, I’m current scripting a restaurant system. But when I want to add bread to the plate it just names the item I’m holding. Instead of switching out the Plate for Plate w/ Bread.

Screenshots:
robloxapp-20210114-1140257.wmv (1.3 MB)

If you are able to help, It would be appreciated!
Kind regards, Scrixptz.

Is their more code than just this? The code that you provided only renames the tool.

The only other code is the Plate giver.

What is the parent of the script? If the bread is getting renamed that means the bread is the part touching the plate not the other way around.

I’m not sure I understand? The bread is meant to touch the plate first, the plate shouldn’t touch the bread?

There is also no parent of the script, It is just a present script.

function tch(h)
if (h.Parent.Name == "Plate") then
wait(3)
-- Give the player a tool with a plate and bread
end

I have created a tool with the bread ontop of the bread. I’m not sure what script to put there to destroy the plate, and give the plate with bread.

Just give the player another tool once the plate touches it and destroy the current tool.

Sorry, I’m very new to scripting and don’t know how to destroy the plate and hand a new tool.

function Tch(hit)
if hit.Parent.Name == "Plate" then
hit.Parent:Destroy() -- Destroy the Plate
local clone = -- Clone the Bread (make sure it is a tool)
clone.Parent = game.Players:GetPlayerFromCharacter(hit.Parent.Parent).Backpack

end
end

script.Parent.Touched:Connect(function(Tch)

I have tried it but now the script doesn’t detect the plate, and nothing happens within the script.

Wait, I made a some typos in the code. Also any errors?

function Tch(h)
if hit.Parent.Name == “Plate” then
hit.Parent:Destroy() “Plate”
local clone = “Bread w/ Plate”
clone.Parent = game.Players:GetPlayerFromCharacter(hit.Parent.Parent).Backpack

end

end

script.Parent.Touched:Connect(function(Tch)

I asking if their are any errors in the output. You can open the output in the view tab

This is the script that just changes the name:

function tch(h)

if (h.Parent.Name == “Plate”) then

wait(3)

h.Parent.Name = “Plate w/ Bread”

end

end

function S(l)

if l.Parent.Name == “Plate” then

end

end

script.Parent.Touched:connect(tch)

wait()

script.Parent.Touched:connect(S)

It says there is an “expected ‘end’ error”.

Ok then, ima edit the comment with the code.

Also, do I add this script to the original script that just changed the name?

I think the error is in the other script. The error in the code was just typo. I edited the script.