Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make an item (Tool) interact with a brick?

Asked by 6 years ago

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!

0
Yeah dude, you are going to need to indent and put the code in the correct lines. The script is confusing to read xd. But from what I am saying, you are trying to compare state(object value) to "empty" (string value). CounterBoy123 53 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

Ad

Answer this question