General > Developers Corner

Changing the global gravity (for players) with Entity:SetGravity() ?

(1/1)

FlyinC4T:
alright so I have been trying out multiple times to get this to work.


--- Code: -----[[
    Gravity Settings--]]
hook.Add("PlayerSpawn", "wzm:GlobalGravity", function()
    Player:SetGravity(100)
end)
--- End code ---

basically it's supposed to set the global gravity for all players. I would use PlayerConnect aswell, but before that I have to make the PlayerSpawn work first.

(I have a bunch of E2 experience and I am aware that it is NOT the same, that being said I should be able to understand at least some stuff)

The Error:

--- Code: ---lua:4: attempt to index global 'Player' (a function value)
--- End code ---


IF IT IS NOT POSSIBLE (read me)
then please do show me alternative ways

DerMetelGamerYT:
Hi, you should try this:


--- Code: -----[[Gravity Settings--]]
hook.Add("PlayerSpawn", "wzm:GlobalGravity", function(player)
    player:SetGravity(100)
end)

--- End code ---

Codingale:

--- Quote from: DerMetelGamerYT on February 16, 2022, 04:10:31 AM ---Hi, you should try this:


--- Code: -----[[Gravity Settings--]]
hook.Add("PlayerSpawn", "wzm:GlobalGravity", function(player)
    player:SetGravity(100)
end)

--- End code ---

--- End quote ---

I advise newcomers to Lua to avoid using globals such as player as if they overwrite the player table they can no longer use things like player.GetAll() and so on, and sometimes they won't even know what's wrong. In most cases I use pl, or ply

Navigation

[0] Message Index

Go to full version