How does _G work and will it function with BoolValues?

So i’ve been thinking of cleaning my messy downed/ragdoll script to make it work everywhere.
And i thought of _G would be best for this.
So i need a little review of my script and see if it’ll function very well
Serverscript returns that player is indeed downed.

-- SERVER SCRIPT
_G.Ragdolled = function()
	if Character:FindFirstChild("Values").Ragdolled.Value == true then
		return true
	elseif Character:FindFirstChild("Values").Ragdolled.Value == false then
		return false
	end
end

--LOCALSCRIPT
if _G.Ragdolled() then
	print(Players.Name.. "Is ragdolled.")
end

Thanks in advance!

the script has no error, it is good, but i think this topic is not for Scripting Support category.

1 Like

Thank you! and yes i’m aware of this not being the right category, but nonetheless i was wondering if _G works with elseif not too!
Here is my script:

if _G.Ragdolled() then
    print(Players.Name .. "Is ragdolled.")
elseif not _G.Ragdolled() then
    print(Players.Name .. "Is no longer ragdolled")
end

yes of course, why not?
it will work.

if we say that it will return false, then not false means true and it will work.

_G is a module script like any other. It is unique to each client and the server, setting _G.my_value = true will not be replicated to clients or the server. The function you defined in your first example will not exist on client scripts.

1 Like

oh i saw it new that one of the scripts is local and the other is server, try using remoteFunctions.

Well when i tried it i got this error Workspace.weakroblox35.LocalScript:48: attempt to call a nil value
Here are the scripts.

--LOCALSCRIPT
if _G.Ragdolled() then
		print("ON")
elseif not _G.Ragdolled() then
		print("OFF")
end
--SERVER SCRIPT
_G.Ragdolled = function()
	if Character:FindFirstChild("Values").Ragdolled.Value == true then
		return true
	elseif Character:FindFirstChild("Values").Ragdolled.Value == false then
		return false
	end
end

yes as he said, look at @gertkeno 's answer.

1 Like

Since _G is only unique to each client, i’ve made the _G.Ragdolled function in a starterplayer localscript instead.

local player = game:GetService("Players")
local localplayer = player.LocalPlayer
local character = localplayer.Character or localplayer.CharacterAdded:Wait()
local values = character:WaitForChild("Values")

_G.Ragdolled = function()
	if values:FindFirstChild("Ragdolled").Value == true then
		return true
	elseif values:FindFirstChild("Ragdolled").Value == false then
		return false
	end
end

Will this replicate to other clients (localscripts) as well?

yes, every client will have a _G.Ragdolled() function, but server will not, as i said, try using remote functions

1 Like

It will work.

Not technically replication since this will make the function for each client on their own, no server back and forth needed.

1 Like

yes, like i said in my answer.

1 Like