Fall service
Hello! Do you bored/can’t/insert_your_reason_here to make fall damage that fulfill that list?:
- Server Side check only
- Does not depend on Humanoid state, Instead checks Velocity of PrimaryPart / Torso
- Customizable damage that depends on material (Even for water)
- Multiple groups that you can create (Earth, Moon, Lobby, etc…)
- SetCustomData for specific player or character (overrides group data)
- Good interface and no memory leaks
Okay, I am too bored to do it! Let’s change this then.
There’s some cons:
- Physic is server based, so fall damage will have small latency (~ 0.2 sec)
- All calculations runs every frame after physic (.Stepped)
I hope this is not affects you, if not - let’s continue.
This is example:
Click
local PlayersService = game:GetService("Players")
local FallService = require(script.FallService)
local DefaultGroup = FallService.new("Default", 5, 0.4, { --last argument is optional
["MaterialsDamage"] = {
["Water"] = 0, -- multiply damage by 0 if fall in water (so 0 damage)
["Fabric"] = 0.75, -- by default all materials have 1 multiplier
["Plastic"] = 1.25,
["Metal"] = 1.5,
}
})
PlayersService.PlayerAdded:Connect(function(player)
DefaultGroup:LinkPlayer(player) --[[
Every time player`s character respawns, on his character will be called Enable
Auto unlink if player left from game
]]
FallService:SetCustomData(player, nil, nil, { --We override MaterialsDamage for player`s character.
["MaterialsDamage"] = {
["Water"] = 0.5, --half damage
}
})
end)
Okay, I hope you understand now, let me describe API:
API
local options = { -- that's how options looks like for now
["MaterialsDamage"] = {}
}
FallService.new(groupName, minDistance, damageMultiplier, options) : FallGroup
FallService:SetCustomData(characterOrPlayer, minDistance, damageMultiplier, options) -- Set data that will be used instead of group data (pass 2 arguments as nil to clear)
FallService:GetCustomData(characterOrPlayer) -- Returns custom data or nil (if custom data is not exist)
FallService:GetGroupOf(characterOrPlayer)
FallService:GetGroup(groupName)
FallService:GetFallSignalFor(characterOrPlayer, inInvocation) --[[
Returns signal, this signal is constant (untill character destroyed / player left).
Pass second argument as true if you call this method in CharacterAdded/PlayerAdded invocation point.
Signal created on :Enable() call for character and on PlayerAdded event for player.
]]
FallGroup:Enable(character) -- Enable fallDamage for character
FallGroup:Disable(character) -- Disable fallDamage for character
FallGroup:LinkPlayer(player) -- Link player`s character to enable
FallGroup:UnlinkPlayer(player) -- Unlink player`s character
FallGroup:Toggle(characterOrPlayer, boolean) -- Enable/Disable (if 1 argument is character) or Link/Unlink (if 1 argument is player)
FallGroup:Destroy() --[[
Call`s UnlinkPlayer for each player in fall group and Disable for each character in fall group.
Also all methods of this FallGroup after destroy will throw error if called
]]
You can get this module here: Link
Are you have suggestions or found bug? Let me know!