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.

4 comments
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
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
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
ohh... now I get it yeah now I know what to do