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

How do I print everyones gravity?

Asked by
YTWolFs 11
3 years ago
Edited 3 years ago

Hello! How can I make a script where when I press a button, it prints everyones gravity value. I know that you might think "Everyone will have the same gravity" but not in my game. I want it to print everyones value and if the value is not 199, or whatever the default value is, the value will be a different color. I know this site shouldn't really be used to request scripts to be made but I really can't figure out how to do it...

Example:

User1: 199
User2: 199
User3: 234
etc.

3 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

next time you ask, you should have already attempted to make a script so we can fix it instead of making you scripts. local script can go inside starterplayerscripts, server in serverscriptservice

this script may have errors as I didn't write it in studio or test it but you can edit and fix errors. should be using a remote function

-- this part in a server script
while wait(100) do -- runs every 100 sec
    for i,v in pairs(game.Players:GetPlayers()) do
        local playerGravity = game.ReplicatedStorage.Events.GetGravity:InvokeClient(v) -- will need to make some of this stuff
        print(playerGravity)
--[[
if you want playername: gravity do
print(v.Name .. ': ' .. playerGravity)
]]
    end
end

================= different script ====================

-- this in a local
function game.ReplicatedStorage.Events.GetGravity.OnClientInvoke()
    return game.Workspace.Gravity -- forgot what the gravity was called u can edit if wrong
end
0
Where it says 'We will need to make some of this stuff' what exactly is it that I need to make? YTWolFs 11 — 3y
0
folder in rep storage called 'Events' and remote function in the folder called 'GetGravity' BulletproofVast 1033 — 3y
0
if you are testing it, make it loop every 5 seconds instead of 100 BulletproofVast 1033 — 3y
0
It doesn't work... YTWolFs 11 — 3y
View all comments (6 more)
0
whats the error? BulletproofVast 1033 — 3y
0
There's no error. Nothing happens at all. YTWolFs 11 — 3y
0
did u wait 2 mins? cause it runs every 100 secs unless you shortened it BulletproofVast 1033 — 3y
0
I shortened it to 5 seconds, but it still doesn't work. YTWolFs 11 — 3y
0
put a print before the loop, right after the while wait(5), after the invoke client, and before return workspace.gravity in local script, which ones print? BulletproofVast 1033 — 3y
0
Nvm, I got it to work. YTWolFs 11 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
-- code on the server
local valuelogger = Instance.new("RemoteEvent",game:GetService("ReplicatedStorage"))
valuelogger.Name = "requester"
local yourbutton = yourbuttonhere

    yourbutton.MouseButton1Down:Connect(function()
        valuelogger:FireAllClients("getlocalgravity")
    end)

    local commands = {
        ["gravityvalue"] = 
        function(player,...)
            local args = {...} local gravity = args[1]
            if typeof(gravity) ~= "number" then 
                player:Kick("invalid arguments") print(player.Name .. " gave invalid arguments for the gravity get command")
            else 
                print("gravity for "..player.Name..": "..tostring(gravity)) 
            end 
        end,

    }
    valuelogger.OnServerEvent:Connect(function(plr,...)
        local args = {...}
        local commandrecieved = false
        for i,v in pairs(commands) do
            if args[1] == i then
                table.remove(args,1)
                commandrecieved = true
                v(plr,args)
            end
        end
        if commandrecieved == false then plr:Kick("invalid remote arguments") end
    end)




-- code on the client
local requesterremote = game:GetService("ReplicatedStorage"):WaitForChild("requester")

local funcs = {
    ["getlocalgravity"] = function() requesterremote:FireServer("gravityvalue",workspace.Gravity) end,
}
requesterremote.OnClientEvent:Connect(function(request)
    for i,v in pairs(funcs) do if request == i then v() end end
end)

i know this is not entirely secure but it will print every player's local gravity value from the client on the server

reply to me if there are any errors or incorrect kicks

0
What is it I need to change in the script? YTWolFs 11 — 3y
0
@MLGwarfare04 YTWolFs 11 — 3y
Log in to vote
0
Answered by
YTWolFs 11
3 years ago
Edited 3 years ago

@MLGwarfare04 What do I do with the script? What do I put where? What lines do I need to change? Please help. Thanks!

Answer this question