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

Why does this local script not work when you play ?

Asked by 8 years ago
local lplayer = game.Players.LocalPlayer

local HumT = lplayer.Character.Torso

local LeftA = lplayer.Character["Left Arm"]
local LeftL = lplayer.Character["Left Leg"]
local RightA = lplayer.Character["Right Arm"]
local RightL = lplayer.Character["Right Leg"]
local Head = lplayer.Character.Head



local RepStore = game:GetService("ReplicatedStorage")


local Players = game:GetService("Players")

function OnPlayerAdded(plr)
    print("Hello!")

local part2 = RepStore.Blocky:Clone()
part2.Parent = game.Workspace



local weld = Instance.new("Weld")
weld.Parent = part2
weld.Part0 = part2
part2.Parent = HumT
weld.Part1 = HumT


weld.C0 = CFrame.new(0,0,0)
weld.C1 = CFrame.new(0,0,0)


end


for _,v in pairs(Players:GetPlayers()) do
    OnPlayerAdded(v)
end

game.Players.PlayerAdded:connect(OnPlayerAdded)


myTable = {LeftA, LeftL, RightA, RightL, Head, HumT}

for i,v in pairs(myTable) do
    v.Transparency = 1
end


RightL:remove()
LeftL:remove()
RightA:remove()
LeftA:remove()
print("Deleting Hats....")


wait(2)

for k,s in pairs(lplayer.Character:GetChildren())do
    if s:IsA("Hat") and Head.face.Texture ~= nil then
        s:Destroy()
        s:remove()
    end
end

for l,r in pairs(lplayer.Character.Head:GetChildren()) do
    if r:IsA("Decal") then
        r:remove()
    end
end

print("Done deleting them!")

Head.CanCollide = false
HumT.CanCollide = false

print("The head is now passable")

local bp = Instance.new("BodyPosition", HumT.Blocky)
bp.MaxForce = Vector3.new(0,100,0)

The Localscript is in StarterGui.

It only works in Roblox Studio. Not in a normal game.

0
Are there any errors in-game? You can check by pressing F9. Pyrondon 2089 — 8y
0
The error on the F9 Dev Console is : -- Players.iDarkGames.PlayerGui.LocalScript:3: attempt to index field "Character" ( a nil value) iDarkGames 483 — 8y

1 answer

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

You're trying to get the character before the character has spawned. This can be easily remedied by adding repeat wait() on line 2:

local lplayer = game.Players.LocalPlayer
repeat wait() until lplayer.Character

local HumT = lplayer.Character.Torso

local LeftA = lplayer.Character["Left Arm"]
local LeftL = lplayer.Character["Left Leg"]
local RightA = lplayer.Character["Right Arm"]
local RightL = lplayer.Character["Right Leg"]
local Head = lplayer.Character.Head



local RepStore = game:GetService("ReplicatedStorage")


local Players = game:GetService("Players")

function OnPlayerAdded(plr)
    print("Hello!")

local part2 = RepStore.Blocky:Clone()
part2.Parent = game.Workspace



local weld = Instance.new("Weld")
weld.Parent = part2
weld.Part0 = part2
part2.Parent = HumT
weld.Part1 = HumT


weld.C0 = CFrame.new(0,0,0)
weld.C1 = CFrame.new(0,0,0)


end


for _,v in pairs(Players:GetPlayers()) do
    OnPlayerAdded(v)
end

game.Players.PlayerAdded:connect(OnPlayerAdded)


myTable = {LeftA, LeftL, RightA, RightL, Head, HumT}

for i,v in pairs(myTable) do
    v.Transparency = 1
end


RightL:remove()
LeftL:remove()
RightA:remove()
LeftA:remove()
print("Deleting Hats....")


wait(2)

for k,s in pairs(lplayer.Character:GetChildren())do
    if s:IsA("Hat") and Head.face.Texture ~= nil then
        s:Destroy()
        s:remove()
    end
end

for l,r in pairs(lplayer.Character.Head:GetChildren()) do
    if r:IsA("Decal") then
        r:remove()
    end
end

print("Done deleting them!")

Head.CanCollide = false
HumT.CanCollide = false

print("The head is now passable")

local bp = Instance.new("BodyPosition", HumT.Blocky)
bp.MaxForce = Vector3.new(0,100,0)


Ad

Answer this question