just finished this “Jumpad” and “Barrier” code that basically pushes the player away everytime its in contact with the player.
however as you can see its very laggy when seen from another player, but its very smooth when seen by the server
local debugging = false
local jumpHeight = 50 --// How much force will the player have
local cooldown = 0.5 --// How much time until the player stops floating
--//Scripting...
local rayPartConfig = require(script.RayLaserConfig)
local CollectionService = game:GetService("CollectionService")
--// Locals^
--// Touch Check
debounce = false
local function onTag(tag)
tag.Touched:Connect(function(hit)
if not debounce then
debounce = true
if (hit.Parent:FindFirstChild('Humanoid')~=nil) then
local char = hit.Parent
local HRP = char:FindFirstChild('HumanoidRootPart')
if debounce then
--// Checking for what the player is currently touching and if its the parent of this script.
--// Code goes here
local target = hit.Parent:FindFirstChild('HumanoidRootPart')
local rayOrigin = hit.Parent.PrimaryPart.CFrame.Position
local rayDirection = tag.CFrame.Position - rayOrigin
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {hit.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.IgnoreWater = true
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
if raycastResult.Normal then
local raycastNormal = raycastResult.Normal
local Att0 = Instance.new('Attachment'):Clone()
local linearVelocity = Instance.new('LinearVelocity'):Clone()
Att0.Name = 'linearVelocityAtt0'
Att0.Parent = HRP
linearVelocity.VelocityConstraintMode = 'Line'
linearVelocity.RelativeTo = 'World'
linearVelocity.LineDirection = raycastNormal
linearVelocity.LineVelocity = jumpHeight
linearVelocity.MaxForce = 100000
linearVelocity.Attachment0 = Att0
linearVelocity.Name = 'jumpadLForce'
linearVelocity.Parent = HRP
if debugging then
--//Visual Ray
local rayPart = rayPartConfig.Part:Clone()
local rayPE = rayPartConfig.PE:Clone()
local rayBeam = rayPartConfig.Beam:Clone()
local rayAtt0 = rayPartConfig.Att0:Clone()
local rayAtt1 = rayPartConfig.Att1:Clone()
--//Locals^
rayPE.Parent = rayAtt0
rayBeam.Parent = rayPart
rayAtt0.Parent = rayPart
rayAtt1.Parent = target
rayBeam.Attachment0 = rayAtt0
rayBeam.Attachment1 = rayAtt1
rayPart.Parent = workspace
local rayPart = workspace:FindFirstChild('rayPart')
rayPart.Position = raycastResult.Position
rayPart.CFrame = CFrame.lookAt(rayPart.Position, target.CFrame.Position)
task.wait(0.05)
workspace:FindFirstChild('rayPart'):Destroy()
rayAtt1:Destroy()
print('['..tag.Name..']',hit.Parent.Name,'bounced off',tag.Name,'at',linearVelocity.LineVelocity,'LineVelocity','from',raycastResult.Distance,'studs')
end
if CollectionService:HasTag(tag,"Tag_Barrier") then
task.wait(cooldown/2)
linearVelocity:Destroy()
Att0:Destroy()
end
if CollectionService:HasTag(tag,"Tag_Jumpad") then
task.wait(cooldown)
linearVelocity:Destroy()
Att0:Destroy()
end
--//^
end
end
end
end
debounce = false
end
end)
end
--// Tag Check
for _, part in (CollectionService:GetTagged("Tag_Jumpad")) do
onTag(part)
end
for _, part in (CollectionService:GetTagged("Tag_Barrier")) do
onTag(part)
end
CollectionService:GetInstanceAddedSignal("Tag_Jumpad"):Connect(function(jumpad)
onTag(jumpad)
end)
CollectionService:GetInstanceAddedSignal("Tag_Barrier"):Connect(function(barrier)
onTag(barrier)
end)
Going to have to be honest, the legacy BodyMovers are still proving more useful during my development than the new ones. Things like RocketPropulsion I have yet to find an alternative for in the new BodyMovers.
So yeah I’d probably switch back to the legacy BodyVelocity until Roblox polishes the new alternatives. (Years from now probably lol)
btw I completely separated the code into a server script and a local script, if anybody was curious about the code and wanted to use it for their own games here you go, you’ll need to use Tag Editor though I heavily suggest to just wait for the Studio Tag Editor that Roblox will be adding soon!
and just a heads-up the barrier uses like 2 modules and its kind of long blablabla, just do a barrier yourself with this code if that’s what you want, or just ask me if you really need it.
DO NOT rotate the part at all, put an attachment inside of the jumppad part and put it where you want the player to go, the script will do the rest, however if you know more than me then feel free to edit the script to whatever you need it to do, i made it this way because i work with a friend and i dont want him to have the need to edit the script and rather just simply move the attachment.
ServerScript for the jumpads:
local debugging = false
--//Scripting...
local CollectionService = game:GetService("CollectionService")
--// Locals^
local function onJumpPad(tag, hit)
local debounce = false
if not debounce then
debounce = true
task.spawn(function()
local char = hit.Parent
local HRP = char:FindFirstChild('HumanoidRootPart')
local Att0 = Instance.new('Attachment'):Clone()
local bodyVelocity = Instance.new('BodyVelocity'):Clone()
local cooldown = tag:GetAttribute("Cooldown")
local attDistance = tag:FindFirstChild('attDistance')
Att0.Name = 'linearVelocityAtt0'
Att0.Parent = HRP
bodyVelocity.P = 3000
bodyVelocity.MaxForce = Vector3.new(400000000, 400000000, 400000000)
bodyVelocity.Velocity = attDistance.CFrame.Position*2
bodyVelocity.Name = 'jumpadLForce'
bodyVelocity.Parent = HRP
task.wait(0.1)
bodyVelocity:Destroy()
Att0:Destroy()
debounce = false
end)
end
end
local function onTagJumpPad(tag)
tag.Touched:Connect(function(hit)
if (hit.Parent:FindFirstChild('Humanoid')~=nil) then
task.spawn(function()
local char = hit.Parent
local HRP = char:FindFirstChild('HumanoidRootPart')
local rayOrigin = hit.Parent.PrimaryPart.CFrame.Position
local rayDirection = tag.CFrame.Position - rayOrigin
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {hit.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.IgnoreWater = true
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
if raycastResult.Normal then
if (hit.Parent:FindFirstChild('Humanoid')~=nil) then
if CollectionService:HasTag(tag, 'Tag_JumpPad') then
onJumpPad(tag, hit)
end
end
end
end
end)
end
end)
end
--// Tag Check
for _, part in (CollectionService:GetTagged('Tag_JumpPad') do
onTagJumpPad(part)
part.Orientation = Vector3.new(0,0,0) --//(in case my dumb brain rotates one of them and have no clue why they arent working properly)
end
CollectionService:GetInstanceAddedSignal('Tag_JumpPad'):Connect(function(jumpad)
onTagJumpPad(jumpad)
jumpad.Orientation = Vector3.new(0,0,0) --//(in case my dumb brain rotates one of them and have no clue why they arent working properly)
end)
I’m very new at coding so if you see any issues do tell me, I would love to learn more.