Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i increase a players jump hieght based on a value?

Asked by 5 years ago

making a game where if a value of this number is higher than 20 it increases jump height but idk how to add this. Here is my script local P = game.Players.Name local Play = game.Workspace.Name local player = game.Players local PS = player.PlayerStats.CurrentValue.Value

while true do if PS > 20 then Play.Humanoid.JumpPower = 100 wait(1)

end end

idk what im doing so if somebody could help me that would be good

0
Play.Humanoid.JumpPower = Play.Humanoid.JumpPower + PS? DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

Values and references

You are assuming that PS is a reference to the Value property. This is not the case. When the Value property changes, PS will not change, and if you change PS, the Value will not update accordingly.

What you must do is just make PS refer to the IntValue/NumberValue object directly, and directly access the Value property.

References

It is important to know the difference between a value and a reference.

You can think of references as holding some memory location.

In Lua, for example, functions are passed by reference.

Here is some code to demonstrate this:

```lua local fn1, fn2, fn1ref;

fn1 = function() for i = 1, 12 do print(i^(1/3)); end end

fn2 = function() for i = 1, 12 do print(i^(1/3)); end end

fn1ref = fn1; print(fn1 == fn1ref, rawequal(fn1, fn1ref)); --> true true print(fn1 == fn2, rawequal(fn1, fn2)); --> false false ```

fn1 and fn1ref contain the same exact function in memory. fn2 is different despite the code, line count, ect, being the same*

Values

Datatypes such as booleans and strings for example, are passed by value, and here is some code to demonstrate how this works:

lua local bool = false; local bool2 = bool; bool = true; print(bool, bool2); --> true false

The variables have different memory allocation, and thus the modification of bool did not modify bool2.

Applying this knowledge into your code, and more

First off, your code is not so good. Your identifiers (variable names, table keys, ect) are misleading.

P is not clear at all, Play can be misleading, player is actually referring to the `Players` service.

Let's clean that portion up.

It might also be a good idea to handle this server side if you have not already. Also don't use a while loop to check if a property changes. Listen for the Changed event instead.

```lua local currentValue = player.PlayerStats.CurrentValue; --// assuming you were able to get the player

currentValue.Changed:Connect(function(newValue) --// newValue is the newValue if (newValue >= 20) then player.Character.Humanoid.JumpPower = 100; end end);

--// modify to needs ```

0
thanks for the help MPforfun 91 — 5y
0
incapaxx you put so much effort into answers Mr_Unlucky 1085 — 5y
Ad

Answer this question