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

How can I make a tool change names and appearance when it comes in contact with another part?

Asked by
AlvinC7 -5
6 years ago

Hey! Sorry, I'm terrible at scripting. Basically, I want a character to be holding a brick, and then when that brick comes in contact with another brick, it changes the name and the appearance. This is what I have so far. The name changes but the meshes don't:

function tch(h) if (h.Parent.Name == "Tool") then h.Parent.Name = "Cooked Tool" wait(0.5) h.Parent.Handle.Mesh.MeshId = "http://www.roblox.com/asset/?id=38963339" h.Parent.Handle.Mesh.TextureId = "http://www.roblox.com/asset/?id=134430675" end end

script.Parent.Touched:connect(tch)

0
Please format your code. PyccknnXakep 1225 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

The problem was you needed to get the players backpack by using GetPlayerFromCharacter.

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent) --Get the player
    if not player then print("Player not found") else --If we cant find the player, we print that it wasn't found. If we did find the player, we continue on with the script.
            local Tool = player.Backpack:FindFirstChild("Tool") --Find the tool name
            if Tool then
            Tool.Name = "Cooked Tool"
            Tool.Handle.Mesh.MeshId = "http://www.roblox.com/asset/?id=38963339"
            Tool.Handle.Mesh.TextureId = "http://www.roblox.com/asset/?id=134430675"
            end
        end

end)

Please accept my answer if this helped!

0
doesnt work AlvinC7 -5 — 6y
0
It does. I tested it myself. PyccknnXakep 1225 — 6y
0
You need to put it inside of the part for it to work. PyccknnXakep 1225 — 6y
Ad
Log in to vote
0
Answered by 3 years ago

well I think instead of changing the mesh id you should change the transparency, it will simplify it. so I used a script for a tutorial, and then changed it. this script is for a key door and makes the door open and close, it access the doors transparency. so I changed it to access the items transparency. It was very simple, all you have to do is make a part transparency 1, or 0 and it would work. this script is a server script ( just a normal script ) inside of any part that you want it to happen. I can also access the tools name easily, here is my script.

script.Parent.Touched:connect(function(p)
 if p.Parent.Name == "Food" then --name of the tool
          p.Parent.Handle.Transparency = 1
        p.Parent.Name = "Test"


 end
end)

Answer this question