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
_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.
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
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?