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

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

Asked by 6 years ago

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?

0
local plr = game.Players:WaitForChild("Xx_XSanderPlayXx") Waits until you load greatneil80 2647 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
code = string.gsub(code, "LocalPlayer", plr.Name, 10000)
loadstring(code)()

I did this!, thx!

Ad

Answer this question