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.
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