Hey guys. I am making a game about brewing Potions. But because of updates the scripts broke. How can I make the items interact. (When you hold an item (Ex: A key) and touch the item it interacts with (Ex: A door))
This is the Code I used to make interaction:
local function OnCardTouch0 (Hit) local Real = Hit:FindFirstChild("Item") local state = script.Parent.State.Value if Real and state == ("empty") then StateChange0() = 0 end end script.Parent.Touched:connect(OnCardTouch0)
Can Someone Help make it more efficient and un-breakable? It also has timed states. They work so it shouldn't be a problem! But if you can make timed states change in a more efficient way, I would love to know that as well! Thanks for your support guys!
You have a key and a door
Part touches Door -> Door changes state
Key.LocalScript, where script.Parent.Part is analogous to Key.Part:
script.Parent.Part.Touched:connect(function(touchedpart) -- okay the tool's part (the key) touched something -- does the touched part have a state (a string value or similar?) local state = touchedpart:FindFirstChild("State") if( state ~= nil )then if( state.Value == "empty" )then -- change state and stuff -- state.Value = "full" elseif( state.Value == "full" )then state.Value = "empty" end end end)
Code not tested in studio for compatibility with features like experimental mode.
If you want help with things like "timed states", you ought to post code pertaining to "timed states" alongside the rest of the code; or, at the very least, a rundown of the process.