I have try over and over and over again so many times but this is the same type of error I'm facing again.They said that 'Character' is a nil value.I don't understand what they mean.
I'm trying to make a projectile get thrown by using UserInputService
.
local player = game.Players.LocalPlayer local Character = player.Character local db = true UIS.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end local KP = Input.KeyCode if KP == Enum.KeyCode.E and db then if db == true then db = false mic:Clone() mic.Name = "MicToss" mic.Parent = Character mic.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0.5,0,-5) local BV = Instance.new('BodyVelocity') BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge) BV.Velocity = Character.Torso.CFrame.LookVector * 100 BV.Parent = mic end end
It is line 14 where I get the error.
its probably because the script ran before the character ran, so if the character doesn't exist then it'll return nil. Use player.CharacterAdded:Wait()
which yields until the character loaded or respawned.
local player = game.Players.LocalPlayer local Character = player.Character or player.CharacterAdded:Wait() local db = true UIS.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end local KP = Input.KeyCode if KP == Enum.KeyCode.E and db then if db == true then db = false mic:Clone() mic.Name = "MicToss" mic.Parent = Character mic.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0.5,0,-5) local BV = Instance.new('BodyVelocity') BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge) BV.Velocity = Character.Torso.CFrame.LookVector * 100 BV.Parent = mic end end