Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I print everyones gravity?

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

✓ Accepted answer

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

10 comments

0

Where it says 'We will need to make some of this stuff' what exactly is it that I need to make?

0

folder in rep storage called 'Events' and remote function in the folder called 'GetGravity'

0

if you are testing it, make it loop every 5 seconds instead of 100

0

It doesn't work...

0

whats the error?

0

There's no error. Nothing happens at all.

0

did u wait 2 mins? cause it runs every 100 secs unless you shortened it

0

I shortened it to 5 seconds, but it still doesn't work.

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?

0

Nvm, I got it to work.

-- 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

2 comments

0

What is it I need to change in the script?

0

@MLGwarfare04

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

This discussion is preserved as it was. New answers, comments, and votes are closed.