Hello, I would like to make a magnitude, that is, the player stands on the part and is given endurance, that is, the player has gained 100 stamina and stands on the part and is given eMulti And I would also like to make it so that when the player is standing on a part, he cannot use the tool until he gets off it. I want them to only work on eMulti But otherwise, I can’t work with the magnitude and I don’t know how
local character = script.Parent
local player = game.Players:GetPlayerFromCharacter(character)
local gui = player.PlayerGui.SafeZoneGui
local root = character.HumanoidRootPart
local radius = 20
local strength = player.Strength
local psp = player.Psp
local endurance = player.Endurance
local sMulti = player.ZoneMulti
local pMulti = player.pZoneMulti
local eMulti = player.eZoneMulti
-- ZONE ROOTS
local rockRoot = game.Workspace.RockZone.Rock
local pspRoot = game.Workspace.TestPsychicZone.Rock
local areRoot = game.Workspace.Pea.Are
local treadmillRoot = game.Workspace.TreadmillZone.treadmill
local bicepRoot = game.Workspace.BicepZone.Bicep
local sandboxRoot = game.Workspace.sandboxZone.sandbox
local qualityRoot = game.Workspace.qualityZone.quality
local elektroRoot = game.Workspace.ElektroZone.elektro
local treeRoot = game.Workspace.TreeZone.tree
local treadmill2Root = game.Workspace.TreadmillZone2.treadmill2
local treadmill3Root = game.Workspace.TreadmillZone3.treadmill3
local bicepRoot2 = game.Workspace.BicepZone2.Bicep2
local bicepRoot3 = game.Workspace.BicepZone3.Bicep3
local libraryRoot = game.Workspace.LibraryZone.library
local libraryRoot2 = game.Workspace.LibraryZone2.library2
local libraryRoot3 = game.Workspace.LibraryZone3.library3
local lavaRoot = game.Workspace.LavaZone.Lava
local bridgeRoot = game.Workspace.BridgeZone.bridge
local policeRoot1 = game.Workspace.PoliceZone.Police
local policeRoot2 = game.Workspace.TrainPoliceZone.Police
local policeRoot3 = game.Workspace.PoliceZone2.police
local policeRoot4 = game.Workspace.TrainPoliceZone2.Police
local PyramidRoot = game.Workspace.PyramidZone.Rock
local PyramidRoot2 = game.Workspace.PyramidZone2.Test
local PyramidRoot3 = game.Workspace.PyramidZone3.Rock
local cactusRoot2 = game.Workspace.CactusZone2.Test
local cactusRoot = game.Workspace.CactusZone.cactus
local pyramidRoot3 = game.Workspace.PyramidZone3.Rock
local pyramidRoot4 = game.Workspace.PyramidZone4.Lava
local snowRoot = game.Workspace.SnowZone1.Rock
local snowRoot2 = game.Workspace.SnowZone2.Rock
local snowRoot3 = game.Workspace.SnowZone3.cactus
local snowRoot4 = game.Workspace.SnowZone4.Rock
local snowRoot5 = game.Workspace.SnowZone5.quality
local snowRoot6 = game.Workspace.SnowZone6.quality
local volcanoRoot = game.Workspace.VolcanoZone.treadmill3
local volcanoRoot2 = game.Workspace.VolcanoZone2.Are
local volcanoRoot3 = game.Workspace.VolcanoZone3.Rock
local volcanoRoot4 = game.Workspace.VolcanoZone4.Bicep3
local volcanoRoot5 = game.Workspace.VolcanoZone5.treadmill3
local volcanoRoot6 = game.Workspace.VolcanoZone6.Rock
local woltRoot = game.Workspace.woltZone.Lava
local woltRoot2 = game.Workspace.woltZone2.Rock
local woltRoot3 = game.Workspace.woltZone3.Rock
local woltRoot4 = game.Workspace.woltZone4.Lava
local woltRoot5 = game.Workspace.WoltZone5.Rock
local woltRoot6 = game.Workspace.WoltZone6.Rock
while wait(0.0000000001) do
-- Reset multipliers
sMulti.Value = 1
pMulti.Value = 1
eMulti.Value = 1
-- Calculate distances
local rockDistance = (root.Position - rockRoot.Position).Magnitude
local pspDistance = (root.Position - pspRoot.Position).Magnitude
local areDistance = (root.Position - areRoot.Position).Magnitude
local treadmillDistance = (root.Position - treadmillRoot.Position).Magnitude
local BicepDistance = (root.Position - bicepRoot.Position).Magnitude
local sandboxDistance = (root.Position - sandboxRoot.Position).Magnitude
local qualityDistance = (root.Position - qualityRoot.Position).Magnitude
local elektroDistance = (root.Position - elektroRoot.Position).Magnitude
local treeDistance = (root.Position - treeRoot.Position).Magnitude
local treadmill2Distance = (root.Position - treadmill2Root.Position).Magnitude
local treadmill3Distance = (root.Position - treadmill3Root.Position).Magnitude
local BicepDistance2 = (root.Position - bicepRoot2.Position).Magnitude
local BicepDistance3 = (root.Position - bicepRoot3.Position).Magnitude
local libraryDistance = (root.Position - libraryRoot.Position).Magnitude
local libraryDistance2 = (root.Position - libraryRoot2.Position).Magnitude
local libraryDistance3 = (root.Position - libraryRoot3.Position).Magnitude
local lavaDistance = (root.Position - lavaRoot.Position).Magnitude
local bridgeDistance = (root.Position - bridgeRoot.Position).Magnitude
local policeDistance1 = (root.Position - policeRoot1.Position).Magnitude
local PoliceDistance2 = (root.Position - policeRoot2.Position).Magnitude
local PoliceDistance3 = (root.Position - policeRoot3.Position).Magnitude
local PyramidDistance = (root.Position - PyramidRoot.Position).Magnitude
local PyramidDistance2 = (root.Position - PyramidRoot2.Position).Magnitude
local CactusDistance = (root.Position - cactusRoot.Position).Magnitude
local CactusDistance2 = (root.Position - cactusRoot2.Position).Magnitude
local PyramidDistance3 = (root.Position - pyramidRoot3.Position).Magnitude
local PyramidDistance4 = (root.Position - pyramidRoot4.Position).Magnitude
local snowDistance = (root.Position - snowRoot.Position).Magnitude
local snowDistance2 = (root.Position - snowRoot2.Position).Magnitude
local snowDistance3 = (root.Position - snowRoot3.Position).Magnitude
local snowDistance4 = (root.Position - snowRoot4.Position).Magnitude
local snowDistance5 = (root.Position - snowRoot5.Position).Magnitude
local policeDistance6 = (root.Position - policeRoot4.Position).Magnitude
local snowDistance6 = (root.Position - snowRoot6.Position).Magnitude
local volcanoDistance = (root.Position - volcanoRoot.Position).Magnitude
local volcanoDistance2 = (root.Position - volcanoRoot2.Position).Magnitude
local volcanoDistance3 = (root.Position - volcanoRoot3.Position).Magnitude
local volcanoDistance4 = (root.Position - volcanoRoot4.Position).Magnitude
local volcanoDistance5 = (root.Position - volcanoRoot5.Position).Magnitude
local volcanoDistance6 = (root.Position - volcanoRoot6.Position).Magnitude
local woltDistance = (root.Position - woltRoot.Position).Magnitude
local woltDistance2 = (root.Position - woltRoot2.Position).Magnitude
local woltDistance3 = (root.Position - woltRoot3.Position).Magnitude
local woltDistance4 = (root.Position - woltRoot4.Position).Magnitude
local woltDistance5 = (root.Position - woltRoot5.Position).Magnitude
local woltDistance6 = (root.Position - woltRoot6.Position).Magnitude
-- Apply multipliers based on location
if rockDistance <= radius and strength.Value >= 100 then -- 100
sMulti.Value = 5
end
if lavaDistance <= radius and endurance.Value >= 100 then -- 100
eMulti.Value = 5
end
if bridgeDistance <= radius and psp.Value >= 100 then -- 100 psp
pMulti.Value = 5
end
if pspDistance <= radius and psp.Value >= 100000000000 then -- 100b psp
pMulti.Value = 125000
end
if areDistance <= radius and strength.Value >= 5000 then -- 5K
sMulti.Value = 20
end
if treadmillDistance <= radius and endurance.Value >= 100000 then -- 100k
eMulti.Value = 100
end
if BicepDistance <= radius and strength.Value >= 100000 then -- 100k
sMulti.Value = 100
end
if sandboxDistance <= radius and psp.Value >= 5000 then -- 5k
pMulti.Value = 20
end
if qualityDistance <= radius and endurance.Value >= 5000 then -- 5k
eMulti.Value = 20
end
if elektroDistance <= radius and endurance.Value >= 100000000000 then -- 100b
eMulti.Value = 125000
end
if policeDistance6 <= radius and strength.Value >= 100000000000 then -- 100b
sMulti.Value = 125000
end
if treeDistance <= radius and psp.Value >= 1000000000 then -- 1B
pMulti.Value = 25000
end
if treadmill2Distance <= radius and endurance.Value >= 5000000 then -- 5m
eMulti.Value = 1000
end
if treadmill3Distance <= radius and endurance.Value >= 1000000000 then -- 1B
eMulti.Value = 25000
end
if BicepDistance2 <= radius and strength.Value >= 5000000 then -- 5m
sMulti.Value = 1000
end
if BicepDistance3 <= radius and strength.Value >= 1000000000 then -- 1B
sMulti.Value = 25000
end
if libraryDistance <= radius and psp.Value >= 5000 then -- 5k psp
pMulti.Value = 20
end
if libraryDistance2 <= radius and psp.Value >= 100000 then -- 100k psp
pMulti.Value = 100
end
if libraryDistance3 <= radius and psp.Value >= 5000000 then -- 5m psp
pMulti.Value = 1000
end
if policeDistance1 <= radius and psp.Value >= 5000000000000 then -- 5t psp
pMulti.Value = 1000000
end
if PoliceDistance2 <= radius and strength.Value >= 5000000000000 then -- 5t
sMulti.Value = 1000000
end
if PoliceDistance3 <= radius and endurance.Value >= 5000000000000 then -- 5t
eMulti.Value = 1000000
end
if PyramidDistance <= radius and psp.Value >= 5000000000000000 then -- 5Qa psp
pMulti.Value = 15000000
end
if PyramidDistance2 <= radius and strength.Value >= 5000000000000000 then -- 5Qa
sMulti.Value = 15000000
end
if PyramidDistance3 <= radius and psp.Value >= 5000000000000000000 then -- 5Qi
pMulti.Value = 100000000
end
if PyramidDistance4 <= radius and endurance.Value >= 5000000000000000000 then -- 5Qi
eMulti.Value = 100000000
end
if CactusDistance2 <= radius and endurance.Value >= 5000000000000000000 then -- 5qi
eMulti.Value = 100000000
end
if CactusDistance <= radius and strength.Value >= 5000000000000000000 then -- 5Qi
sMulti.Value = 100000000
end
if CactusDistance2 <= radius and endurance.Value >= 5000000000000000000 then -- 5qi
eMulti.Value = 100000000
end
if PyramidDistance4 <= radius and psp.Value >= 5000000000000000 then -- 5Qd psp
pMulti.Value = 15000000
end
if snowDistance <= radius and psp.Value >= 1000000000000000000000 then -- 1sx psp
pMulti.Value = 2500000000
end
if snowDistance2 <= radius and psp.Value >= 7000000000000000000000000 then -- 7sp psp
pMulti.Value = 75000000000
end
if snowDistance3 <= radius and strength.Value >= 1000000000000000000000 then -- 1sx
sMulti.Value = 2500000000
end
if snowDistance4 <= radius and strength.Value >= 7000000000000000000000000 then -- 7sp
sMulti.Value = 75000000000
end
if snowDistance5 <= radius and endurance.Value >= 1000000000000000000000 then -- 1sx
eMulti.Value = 2500000000
end
if snowDistance6 <= radius and endurance.Value >= 7000000000000000000000000 then -- 7sp
eMulti.Value = 75000000000
end
if volcanoDistance <= radius and endurance.Value >= 3000000000000000000000000000 then -- 3oc
eMulti.Value = 1000000000000
end
if volcanoDistance2 <= radius and strength.Value >= 3000000000000000000000000000 then -- 3oc
sMulti.Value = 1000000000000
end
if volcanoDistance3 <= radius and psp.Value >= 3000000000000000000000000000 then -- 3oc psp
pMulti.Value = 1000000000000
end
if volcanoDistance4 <= radius and strength.Value >= 5000000000000000000000000000 then -- 5n
sMulti.Value = 1000000000000000
end
if volcanoDistance5 <= radius and endurance.Value >= 5000000000000000000000000000 then -- 5n
eMulti.Value = 1000000000000000
end
if volcanoDistance6 <= radius and psp.Value >= 5000000000000000000000000000 then -- 5N psp
pMulti.Value = 1000000000000000
end
if woltDistance <= radius and endurance.Value >= 3000000000000000000000000000000 then -- 3Dc
eMulti.Value = 250000000000000000
end
if woltDistance2 <= radius and psp.Value >= 3000000000000000000000000000000 then -- 3Dc psp
pMulti.Value = 250000000000000000
end
if woltDistance3 <= radius and psp.Value >= 100000000000000000000000000000000000 then -- 1Dd psp
pMulti.Value = 50000000000000000000
end
if woltDistance4 <= radius and endurance.Value >= 100000000000000000000000000000000000 then -- 3Dc
eMulti.Value = 50000000000000000000
end
if woltDistance5 <= radius and strength.Value >= 3000000000000000000000000000000 then -- 3Dc
sMulti.Value = 250000000000000000
end
if woltDistance6 <= radius and strength.Value >= 100000000000000000000000000000000000 then -- 3Dc
sMulti.Value = 50000000000000000000
end
end
And I would also like to make it so that when a player, for example, does not have 100 endurance, his HP starts to be taken away. Help me do it.
I have never worked with Magnitude, I repeat again and I don’t know what it is, I read the documentation and don’t understand
I won’t try to wrap my head around the other stuff in this post, because it is simply a mess. But I can tell you what magnitude is.
Magnitude (alternatively distance) is the unsigned distance between two points in space. To keep it as simple as possible I’ll use a one axis only example.
- If a = 0 & b = 1 then the distance (difference) between those two is equal to 1, which is logical, one minus zero is equal to one. (When we talk about distance we usually say the target position minus the origin, in this case, b - a)
- If we swap the values around (a = 1 & b = 0) then our calculation would become 0 - 1, which obviously is (-1), however this is not what we actually want. We want to get the distance (difference) between two points, which will always be unsigned, imagine wanting to know how many apples you ate (starting with one and then eating one), and concluding that you ate (-1) apples, no, you still ate one apple! (The distance between the two amounts)
Well, how may we solve the issue at the end of example two? Easy, we just get the absolute value of b minus a, which result in our formula becoming |b - a| , the vertical bars in math means absolute value (unsigned / always positive). In game development we tend to use two vertical bars ||b - a|| to show that we are talking about distance between two points in space and not just some random absolute value, such as how many pears David ate.
In most languages there already is a built-in function for getting the absolute value (in Lua/Luau is is math.abs). If that is not the case, meaning there is no built-in function for absolute value (or if you just want to know how computers make any number positive), then you would do the square root of x square (see image).
If we were to bake this into our original formula |b - a| then we’d get:
I understand this, but how to write this in the script? I don’t know how to write magnitude in the script.
Roblox (as with most game engines) comes with it built in, for Roblox you just have to do:
(Vector - Vector).Magnitude
Could you make an example on my script, then I will continue writing myself
I want that when the player gets on the part he will receive endurance and when he gets off it he will not receive endurance and when he has little endurance his HP will be gradually taken away
I would approach the endurance and HP parts as two different parts, aka not mashing them into one big script, this way of approaching things makes it easier to work with and maintain in the future.
The thing about programming / scripting is that there most of the time are a lot of different ways of approaching problems, and you should ultimately choose the way that works the best for you, however, one way of approaching the endurance part could be:
local Players = game:GetService("Players")
local PART = script.Parent -- Size and position a part according to the area of where players shall receive endurance
local function giveEndurance()
local parts = workspace:GetPartsInPart(PART)
if (#parts >= 6) then
local alreadyGiven = {}
for _,part in pairs(parts) do
local plr = Players:GetPlayerFromCharacter(part.Parent)
if not plr then continue end
if table.find(alreadyGiven, plr.Name) then continue end
table.insert(alreadyGiven, plr.Name)
-- Code to add to their endurance
end
end
task.wait(2)
giveEndurance()
end
giveEndurance()
I have several questions, 1 of them is where to write this, 2 is it possible to make it so that when you are standing on the endurance part, you cannot use the tool, that is, get a boost from it
-
Read the third line of the script to know where I placed it for testing purposes, if you are planning to have multiple parts doing the same thing in your game, then the best would be to manage all of them from ServerScriptService using CollectionService.
-
You can do anything that the Roblox engine allows you to (short answer: Yes.)
To be honest, I don’t understand scripts.
I am studying the base and with some help I was able to create this script
I thought they would help me with the script, I don’t understand English at all, I’m sitting with a translator, to be honest
I thought you would write in the script what and how what is responsible for what, that is, endurance auto-pumping is meant
Perhaps you should start at the bottom and work your way up then. Programming / scripting is not about memorizing code snippets nor to know every built-in api by heart, it is about problem solving, programmers are problem solvers, and problems can be solved in multiple ways.
If you become good at debugging and searching the wide web, then you’re basically unstoppable in the programming space, even if sometimes takes a year or more, eventually you’ll get it working 99.99% of the time.
Could you write to me in my script auto pumping endurance I created a topic for this so that they could help with the script what is responsible for what and not say what and how I honestly do not understand what you wrote
Endurance could refer to many different things depending on where you’re coming from, i.e endurance in a fighting game, or the indurance of a material, so in this case I just see it as a random number to be increased.
Have you played super power fighting simulator?