Coffee machine script issue

I’m basically making a coffee machine, when you touch it with a tool of a specific name, it renames it and the machine functions.

Unfortunately, what I am experiencing is the fact that when the tool is in starter gear when I touch the machine with it it works, but if I touch the machine with a cup that I got from the cup giver it doesn’t work. It’s really strange and I’m not getting any errors.

I have tried moving the tool to server storage instead of replicated storage, but then I get an error saying the specific tool is nill. (Also let me note, I didn’t forget to make changes in the script for that)

Cup Giver Script (located in replicated first, local script):

local Player = game:GetService("Players")
local Mouse = Player.LocalPlayer:GetMouse()
local GroupID = 6164563
local MinimumRank = 3

function PickUp(Item)
	if Mouse.Target == script.Target.Value and Player.LocalPlayer:GetRankInGroup(GroupID) >= MinimumRank and script.Cooldown.Value == false then
		script.Cooldown.Value = true
		local Backpack = Player.LocalPlayer.Backpack
		local Item = script.Tool.Value
		Item:Clone().Parent = Backpack
		if script.Target.Value:FindFirstChild("SoundEffect") then
		script.Target.Value.SoundEffect:Play()
		end
		wait(1)
		script.Cooldown.Value = false
	end
end

Mouse.Button1Up:Connect(PickUp)

Coffee Machine Script:

function tch(h)
	if (h.Parent.Name == "Takeaway Cup") and h.Parent:IsA("Tool") then
		script.Parent.Activate:Play()
		script.Parent.Liquid.Transparency = 0
		h.Parent.Name = script.Parent.Parent.Name
		wait(0.5)
		script.Parent.Liquid.Transparency = 1
	end
end

script.Parent.Touched:Connect(tch)

Really would appreciate some help!

For the Coffee machine script I’d recommend you detect if a player touched it, then check if they have that tool. It’s probably more accurate then detecting for a specific tool which is a lot smaller.

Also you should add a debounce

1 Like

I’ll have to try that, I’ll update you if it works.

1 Like

What is the name of the cup you retrieve from the cup giver? Is it also Takeaway Cup or is it named differently?

Also I think the issue is that the tool is local since your cloning it from a localscript and probably the machine isn’t detecting it. Can’t you use a ClickDetector and create a regular script to detect when someone clicks the clickdetector?

1 Like

The name of the tool is “Takeaway Cup”.

Also, yes. You’re right. I might do a clickdetector instead.

1 Like

Alright, let’s hope it works! If needed, I can help you out if you’re unsure of how to do it! Remember that MouseClick returns the player who clicked the detector!

1 Like

Yup, thank you! Hoping that works.

1 Like

This was much better, thank you!

1 Like

Anytime! if you have anymore issues don’t be afraid to make another post!

1 Like