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

Do I can change LocalPlayer to my player in a global script?

I'm trying to do a script builder, instead of game.Players.LocalPlayer to game.Players.Xx_XSanderPlayXx.

this is what i tried

function Run(f, plr)
	local unfunction,message = loadstring(f)
	if not unfunction then
		return nil, message
	end
	
	local oldEnvironment = getfenv(unfunction)
	
	local NewEnvironment = setmetatable({}, {
		__index = function(_, k)
			if k:lower() == "localplayer" then
				print(k)
				oldEnvironment[k] = plr.Name
				return oldEnvironment[k]
			else
				return oldEnvironment[k]
			end
		end	
	})
	
	setfenv(unfunction, NewEnvironment)
	unfunction()
end

it only works with game.Players[LocalPlayer].

Can someone help me please?

1 comment

0

local plr = game.Players:WaitForChild("Xx_XSanderPlayXx") Waits until you load

1 answer

code = string.gsub(code, "LocalPlayer", plr.Name, 10000)
loadstring(code)()

I did this!, thx!

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