Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I make an axe hit wood and get wood for a survival game?

I'm making a survival game and I made the axe tool but how would I script it to get wood when I hit a Part? (If you answer this question you will answer a lot of problems that I have with making a game..)

3 comments

0

I'm sorry, but ScriptingHelpers is a site where we solve errors inside scripts, not make scripts from scratch for people. Please create a script, test it, and if it fails, submit the script with the output...

0

@TheArmoredReaper, it is also for helping scripters get pointed in the right direction, though that usually involves them showing us the mistake(s) they had made before.

0

--Define the equipped tool, this is assuming you welded it and are not using tools. from drahsid5. Can u explain what that means please. New to scripting xD

1 answer

This is simple.

You wait use the Mouse.Button1Down() function and the BasePart.Touched() function, and if the brick that it hits is named something like "Wood" or whatever, then you would add +1 wood to the inventory. Like:

materials = { --Make an array to hold the variables for the materials
[1]={"Wood",0}, --Each table has the amount owned, and name of the material
[2]={"Stone",0}
}

mouse = game.Players.LocalPlayer:GetMouse() --Define the player's mouse

tool = game.Players.LocalPlayer.Pick.Core --Define the equipped tool, this is assuming you welded it and are not using tools.

mouse.Button1Down:connect(function() --Left mouse click
--Swing animation

tool.Touched:connect(function(hit) --The tool touched something?
if hit.Name == "Wood" then --If it's wood
materials[1][2] = (materials[1][2]+1) --Add to wood
elseif hit.Name == "Stone" then --If it's stone
materials[2][2] = (materials[2][2]+1) --Add to stone
end
end)
end)

Sources: Mouse.Button1Down() http://wiki.roblox.com/index.php?title=API:Class/Mouse/Button1Down BasePart.Touched() http://wiki.roblox.com/index.php?title=API:Class/BasePart/Touched Tables http://wiki.roblox.com/index.php?title=Table GetMouse() http://wiki.roblox.com/index.php?title=API:Class/Player/GetMouse

3 comments

0

You are using a Dictionary not a array.

0

lel drah answering requests to get rep

0

If only I can downvote...

This discussion is preserved as it was. New answers, comments, and votes are closed.