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

I Don't understand, I got everything set up but It wont work in player?

Asked by 6 years ago

So I made a script that uses clothes when you spawn and it works PERFECTLY when i press play on Roblox studio it works fine but when I play in a real game it does not work! (filtering not enables)

is is what i have:

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(char)
game.Players.LocalPlayer.PlayerGui.ScreenGui.GOB.Girl.MouseButton1Click:connect(function()
game.Players.LocalPlayer.PlayerGui.ScreenGui.BegineChoose.Prisoners.MouseButton1Click:connect(function()
    print("hello")
        Delay(1, function()
        local stuff = char:GetChildren()

        for i = 1,#stuff do
            if stuff[i].ClassName=="Hat" or stuff[i].ClassName == "ShirtGraphic" or stuff[i].ClassName=="Pants" or stuff[i].ClassName == "Shirt" or stuff[i].ClassName == "BodyColors" or stuff[i].ClassName == "CharacterMesh" --[[ do you want charactermesh to be removed? Else put it out!--]] then
            stuff[i]:Remove()
            end
        end
        local stuff1 = char.Torso:GetChildren()
        for i = 1,#stuff1 do
            if stuff1[i].ClassName=="Decal" then
                stuff1[i]:Remove()
            end
        end

        local hat1 = game.ServerStorage.UniformG.Hats1:GetChildren()
        if #hat1 >0 then
        local i = math.random (1,#hat1)
        hat1[i]:Clone().Parent=char
        hat1[i].Handle.Position = char.Head.Position
        end

        local hat2 = game.ServerStorage.UniformG.Hats2:GetChildren()
        if #hat2 >0 then
        local i = math.random (1,#hat2)
        hat2[i]:Clone().Parent=char
        hat2[i].Handle.Position = char.Head.Position
        end


        local hat3 = game.ServerStorage.UniformG.Hats3:GetChildren()
        if #hat3 >0 then
        local i = math.random (1,#hat3)
        hat3[i]:Clone().Parent=char
        hat3[i].Handle.Position = char.Head.Position
        end

        local shirts = game.ServerStorage.UniformG.Shirts:GetChildren()
        if #shirts >0 then
        local i = math.random(1,#shirts)
        shirts[i]:Clone().Parent=char
        end

        local Pants = game.ServerStorage.UniformG.Pants:GetChildren()
        if #Pants >0 then
        local i = math.random (1,#Pants)
        Pants[i]:Clone().Parent=char
        end     

        local bodycolor = game.ServerStorage.UniformG.BodyColors:GetChildren()
        if #bodycolor >0 then
        local i = math.random(1,#bodycolor)

        char:FindFirstChild("Head").BrickColor = bodycolor[i].Value
        char:FindFirstChild("Left Arm").BrickColor = bodycolor[i].Value
        char:FindFirstChild("Left Leg").BrickColor = bodycolor[i].Value
        char:FindFirstChild("Right Arm").BrickColor = bodycolor[i].Value
        char:FindFirstChild("Right Leg").BrickColor = bodycolor[i].Value
        char:FindFirstChild("Torso").BrickColor = bodycolor[i].Value    
        end

        local faces = game.ServerStorage.UniformG.Faces:GetChildren()
        if #faces > 0 then
        local stuff2 = char.Head:GetChildren()
        for i =1,#stuff2 do
            if stuff2[i].ClassName=="Decal" then
                stuff2[i]:Remove()
            end
        end

        local i = math.random(1,#faces)
        faces[i]:Clone().Parent=char.Head   
        end

        local packages = game.ServerStorage.UniformG.Package:GetChildren()
        if #packages > 0 then
        local i = math.random (1,#packages)
        local stuff3 = packages[i]:GetChildren()
        for i = 1, #stuff3 do
            stuff3[i]:Clone().Parent=char
            end
            end
        end)
        end)
        end)
        end)        
    end)


0
You can't access PlayerGui via ServerScript m8 gmatchOnRoblox 103 — 6y
0
Is this script server or local? AyeeAndrxw 35 — 6y
0
Hmm it cant be local script and has to be in starter player scripts aliencombat911 -5 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

First of all,

game.Players.LocalPlayer

is only accessible from the Client, in Filtering Enabled.

Some parts of your script is FE compatiable and some isn't.

You should think about structuring your code, so first of all you need to look at the fact that this is non FE. This means that everything can be done from a LocalScript in StarterPlayer.

Another thing is that

:connect

is deprecated, you should be using

:Connect

You seem to want to change the clothes based on which GUI you choose. Here's how I would do this (local script in game.StarterPlayer.StarterPlayerScripts

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild('PlayerGui')
local GUIButton = PlayerGui.-- Locate this to your GUI button

GUIButton.MouseButton1Click:Connect(function()
    if Player.Character then -- Checks if there is a Character
        -- Do your custom changes.
    end
end)
0
The Only thing is you press two gui's insted of 1 fireburnpokemon 16 — 6y
0
So you need to press 2 guis to change the clothes? AyeeAndrxw 35 — 6y
0
Does not work nvm the ansewer sorry.. i think it has to do with char cuz it says undifiend global fireburnpokemon 16 — 6y
0
Yes fireburnpokemon 16 — 6y
0
It proebly will work but not with the script im using fireburnpokemon 16 — 6y
Ad
Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
6 years ago
Edited 6 years ago

To begin with, you should probably used WaitForChild() instead of FindFirstChild() for the character because the character doesn't load all in at once. Because this is a local script, the PlayerAdded event is unnecessary. You should also put the uniforms in ReplicatedStorage because local scripts cannot access ServerStorage. Below, I have refactored the code a little bit by implementing the fixes, removing deprecated functions and adding more variables to increase readability.

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("ScreenGui")
local repStorage = game.ReplicatedStorage
local uniformG = repStorage:WaitForChild("UniformG")

player.CharacterAdded:connect(function(char)
    local torso = char:WaitForChild("Torso")
    local head = char:WaitForChild("Head")
    local leftArm = char:WaitForChild("Left Arm")
    local rightArm = char:WaitForChild("Right Arm")
    local leftLeg = char:WaitForChild("Left Leg")
    local rightLeg = char:WaitForChild("Right Leg")


    screenGui.GOB.Girl.MouseButton1Click:Connect(function()
        screenGui.BegineChoose.Prisoners.MouseButton1Click:Connect(function()
            wait(1)
            for i , v in pairs(char:GetDescendants()) do
                if v:IsA("CharacterAppearance") or v:IsA("Accoutrement") then
                    v:Destroy()
                end
            end

            for i , v in pairs(torso:GetDescendants()) do
                if v:IsA("Decal") then
                    v:Destroy()
                end
            end

            local hat1 = uniformG.Hats1:GetChildren()
            if #hat1 > 0 then
                local i = math.random (1,#hat1)
                hat1[i]:Clone().Parent=char
                hat1[i].Handle.Position = char.Head.Position
            end

            local hat2 = uniformG.Hats2:GetChildren()
            if #hat2 > 0 then
                local i = math.random (1,#hat2)
                hat2[i]:Clone().Parent=char
                hat2[i].Handle.Position = char.Head.Position
            end


            local hat3 = uniformG.Hats3:GetChildren()
            if #hat3 > 0 then
                local i = math.random (1,#hat3)
                hat3[i]:Clone().Parent=char
                hat3[i].Handle.Position = char.Head.Position
            end

            local shirts = uniformG.Shirts:GetChildren()
            if #shirts > 0 then
                local i = math.random(1,#shirts)
                shirts[i]:Clone().Parent=char
            end

            local Pants = uniformG.Pants:GetChildren()
            if #Pants > 0 then
                local i = math.random (1,#Pants)
                Pants[i]:Clone().Parent=char
            end     

            local bodycolor = uniformG.BodyColors:GetChildren()
            if #bodycolor > 0 then
                local i = math.random(1,#bodycolor)
                head.BrickColor = bodycolor[i].Value
                leftArm.BrickColor = bodycolor[i].Value
                leftLeg.BrickColor = bodycolor[i].Value
                rightArm.BrickColor = bodycolor[i].Value
                rightLeg.BrickColor = bodycolor[i].Value
                torso.BrickColor = bodycolor[i].Value    
            end

            local faces = uniformG.Faces:GetChildren()
            if #faces > 0 then
                for i , v in pairs(head:GetChildren()) do
                    if v:IsA("Decal") then
                        v:Destroy()
                    end
                end
                local i = math.random(1,#faces)
                faces[i]:Clone().Parent = head  
            end

            local packages = uniformG.Package:GetChildren()
            if #packages > 0 then
                local i = math.random (1 , #packages)
                for i , v in pairs(packages[i]:GetChildren()) do
                    v:Clone().Parent = char
                end
            end
        end)
    end)
end)   
0
Should work but when i put a print after the first 2 functions(after you press the gui) it did not print fireburnpokemon 16 — 6y

Answer this question