Vending machine flavours

Okay, so I am making smoothies and there is multiple flavours, they start by getting milk and everything works fine, but when it goes to one of the flavours it only changes the name and not the colour based on the flavour.

The script is:

function tch(h)
if (h.Parent.Name == "Milk") then
h.Parent.Name = "MangoSmoothie"
wait(0.5)
h.Drink.BrickColor = script.Color.Value
h.Drink.Transparency = 0
end
end

script.Parent.Touched:connect(tch)

The script links to a value, and the value has colours.
image

The colour is different per flavour however when I try to run the script I get the following error:

What?

  • 30 chars --------------------- -

Can you please provide us with what you are defining ‘h’ as?

(FYI, You’re calling a mesh part. Check the naming you are using.

1 Like

It changes the name from Milk to Mango smoothie on touch.

I’d appreciate if you can do this so I can help you.

Hello @hireimgeorge!

function tch(h)
if (h.Parent.Name == "Milk") then
h.Parent.Name = "MangoSmoothie"
wait(0.5)
h.Parent.Drink.BrickColor = script.Color.Value
h.Parent.Drink.Transparency = 0
end
end

try this

Without it it does not change the name from milk to mango smoothie

The model is not called ‘Milk’ to begin with

It doesn’t need to be, it starts of as cup, then it goes to milk then the script checks if the name is milk and if it is it changes the name to Mango Smoothie and is supposed to change the colour,

So the steps before changing the model is ‘mango smoothie’ works?

I don’t understand what your saying lol.

Does this work or no? (30 chars)

Yes! It changes the name in your inventory from Milk to Mango Smoothie, all I need is for it to change the colour of the invisible part known as drink to the colour that is connected to the value, making the transparency to 1 and changing the colour to the one linked to the script like I showed in the screenshots.

Could you show me how you change the color value?

h.Parent.Drink.BrickColor = script.Color.Value

I think your problem is that “Mango” in Explorer is not a MeshPart. It’s a model. It looks like you’re trying to contact a MeshPart in your script instead of the model.

Edit: this has already been mentioned, nevermind!

How can I fix that in the script?

function tch(h)
if (h.Parent.Name == "Milk") then
h.Parent.Name = "MangoSmoothie"
wait(0.5)
h.Parent.Drink.BrickColor = script.Color.Value
h.Parent.Drink.Transparency = 0
end
end

If you already tried this, ignore this

What are you trying to define as “h” in the script? I’m still confused as to what “h” is.