Tools and teams
Tools
A Tool is something a player holds and uses: a sword, a pickaxe, a torch. Its parts go inside it; the one named Handle is held in the hand, and every other part straight inside the Tool is drawn with it, standing against the Handle as you built it (a sword's guard, a pickaxe's head).
Making a tool in KHIM Engine
- Insert a Tool (Insert Object > Players > Tool) in ReplicationService or StorageService.
- Inside it, build the tool from parts. Name the part the hand holds Handle. With the arm pointing ahead, the Handle's Y is up and its Z forward.
- Give it to players from a Script (below).
At most 32 parts a tool, each up to 8 units.
Giving tools
Tools in a player's backpack show in the hotbar at the bottom of the screen; players pick one with a click or 1-9, 0.
-- Script: everyone gets a sword when they join
players.joined:connect(function(player)
shared.Sword:clone().parent = player.backpack
end)Tools in game.starterPack are copied to every player's backpack when they join:
shared.Sword:clone().parent = game.starterPackUsing a tool
| Member | |
|---|---|
activated | The player clicked the world while holding it (fires on the server) |
equipped, unequipped | Taken out / put away |
enabled | Off: clicking does nothing |
toolTip | The hotbar's tooltip |
The simplest way to know who swings is to connect when you give the tool:
-- Script (ServerService)
players.joined:connect(function(player)
local sword = shared.Sword:clone()
sword.parent = player.backpack
local lastSwing = 0
sword.activated:connect(function()
if time() - lastSwing < 0.5 then return end -- a cooldown
lastSwing = time()
for _, other in players.all() do
if other.name ~= player.name and (other.position - player.position).magnitude < 6 then
other:damage(20)
end
end
end)
end)From a script: player:equipTool(tool) puts a tool in their hand, player:unequipTools() puts it away.
Teams
A Team is a side players are on. It shows in the player list, in the team's colour, and colours the names over players' heads.
- Insert Teams (Insert Object > Players > Team). Wherever one is in the world, it is one of the game's teams.
- Name each, set its Color, and tick AutoAssignable for the teams new players may join.
New players join the smallest auto-assignable team. From a Script:
local red = world.Red -- a Team inserted in the World
player.team = red -- move a player
player.neutral = true -- no team
for _, p in red:getPlayers() do -- everyone on a team
p:teleport(world.RedBase.position + vec3(0, 4, 0))
end| Member | |
|---|---|
color | The team's colour |
autoAssignable | New players may be put on it |
getPlayers() | Who is on it |
A team's own door
Every character is in the Players collision group, whatever its team, so a door can't let one team through by collision alone. Check the team instead. Here the Red base's door is walk-through (CanCollide off), and anyone not on Red who touches it is sent back out:
local door = world.RedDoor
door.touched:connect(function(hit)
local player = players.fromPart(hit)
if player and (player.team == nil or player.team.name ~= "Red") then
player:teleport(world.Lobby.position + vec3(0, 4, 0))
end
end)