Adorations! So I have created a cafe system, however, the system doesn’t work. I will show you the script, and lead you along the way.
local TouchPart = script.Parent.TouchPart
TouchPart.Touched:Connect(function(Hit)
if Hit.Parent.Name == "Large Cup" then
Hit.Parent.Name = "Large Water"
elseif Hit.Parent.Name == "Medium Cup" then
Hit.Parent.Name = "Medium Water"
elseif Hit.Parent.Name == "Small Cup" then
Hit.Parent.Name = "Small Water"
end
end)
So basically, all the variables and everything is correct, and there are no errors in the output. I have no idea what could be going on? (I am also at school, so if I don’t respond for a few minutes, or I can’t try it out, that’s why.) [I also need this asap, because the game releases tomorrow, and I don’t have the system ready.]
What is hit? Print out hit:GetFullName(), this will tell you exactly what is firing the event as well as showing you the path to the instances location.
So when the Touched event fires, which it does, it doesn’t name the cup, which is the overall goal. This script is super simple, hence why I went on here to ask why it is not working as intended.
I’d be 99% sure it would be the cup’s name. (I have tested it with the first instance in the if statement, and it doesn’t work, so it is most likely something to do with the cup, or the player’s character interfering with it.)
Don’t make a post asking for debugging help if you can’t be present to test. Your issue is that the parent is not called Large Cup or whatever.
I would add a string value to your tool called “Prefix” and another called “ToolType”. Set your Prefix value to “Large”, “Medium”, etc and ToolType to “Cup” or something similar.
Then on touch check if the ToolType exists and if it is “Cup” - if it is a cup then set the tool name to Tool.Prefix.Value .. ‘ Water’.
function onTouch(hit)
local parent = hit.Parent
if not parent:IsA(‘Tool’) then return end
-- check to make sure the values actually exist in the tool
-- validation checks
parent.Name = Prefix.Value .. ‘ Water’
end
I will be testing this upon me getting home. I am very sure this would work, but I will get back to you as soon as I can! (You will be marked solution for now, and I will come back if there are errors!)
local TouchPart = script.Parent:WaitForChild("TouchPart")
TouchPart.Touched:Connect(function(Hit)
if Hit.Parent:IsA("Tool") then
if Hit.Parent.Name == "Large Cup" then
Hit.Parent.Name = "Large Water"
elseif Hit.Parent.Name == "Medium Cup" then
Hit.Parent.Name = "Medium Water"
elseif Hit.Parent.Name == "Small Cup" then
Hit.Parent.Name = "Small Water"
end
end
end)
Remember that Tool instances don’t have the “Touched” event (the parts inside them do), also make sure the BasePart instances inside the tools have the “CanTouch” property enabled.