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

:30:attempt to index local 'inputObject' (a nil value)?

Asked by 5 years ago
Edited 5 years ago

I have a problem with the userInputService and I'm not sure how it works so here I am asking. My goal here is to make a building system.

this is the whole script:

local stone = script.Parent.stone.Value
local log = script.Parent.log.Value
local barracks = game.ReplicatedStorage.buildable.barracks
local players = game:GetService("Players")
local player = players.LocalPlayer
local char = player.Character
local mouse = player:GetMouse()

local pos = Instance.new("Part", char)
pos.Name = "pos"
pos.Position = Vector3.new(char:WaitForChild("HumanoidRootPart").Position.X, char:WaitForChild("HumanoidRootPart").Position.Y * -3, char:WaitForChild("HumanoidRootPart").Position.Z)

wait()

local weld = Instance.new("Weld",pos)
weld.Part0 = char:WaitForChild("HumanoidRootPart")
weld.C0 = char:WaitForChild("HumanoidRootPart").CFrame
weld.Part1 = pos
weld.C1 = pos.CFrame
pos.CFrame = char:WaitForChild("HumanoidRootPart").CFrame * CFrame.new(0, 0, 0)

script.Parent.resources.Text = "stones" .. stone .. "logs" .. log

if script.Parent.craft.MouseButton1Click then
    newbarracks = barracks:Clone()
    newbarracks.Parent = workspace
end

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.G then
        newbarracks.anchor.Value = true
    end
    if newbarracks.anchor.Value == false then
        wait(0.1)
        local posy, posx, posz = pos.Position.Y, pos.Position.X, pos.Position.Z
        newbarracks:MoveTo(Vector3.new(posx, posy + 0 , posz))
    end
end

while wait() do
    onKeyPress()
end


if script.Parent.craft.Text.Changed then
    script.Parent.craft.TextWrapped = false
    wait()
    script.Parent.craft.TextWrapped = true
end




any help would appreciated.

1 answer

Log in to vote
0
Answered by
Miniller 562 Moderation Voter
5 years ago
Edited 5 years ago

The UserInputService.InputBegan should call that function on line 30. So e.g

game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == ....
end)

I just wanted to say only the InputBegan event should call a function with inputObject and gameProcessedEvent arguments

0
I have a problem still... cause I need it to fire even if there were no input for the object to follow the pos named part n1ksutin123 3 — 5y
0
I don't really understand you.. You use UserInputService for detect thing like key press, mouse click.. To just get the mouse, you can use player:GetMouse() - but I don't know if you can get the position of the mouse with that Miniller 562 — 5y
0
sorry I didn't think cause I wan't a part inside the player to be the pos of the building... 9, 10 and 11 are for the part that is the position of the building so... its a bit complicated n1ksutin123 3 — 5y
1
ohh... now I get it yeah now I know what to do n1ksutin123 3 — 5y
Ad

Answer this question