I am trying to make so you can move a part with a tool, but nothing happens.. Please help:
Local script (Inside a tool):
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local down = false local tool = script.Parent tool.Equipped:Connect(function(mouse) if mouse.Target ~= nil then mouse.Button1Down:Connect(function() down = true part = mouse.Target end) end if down then mouse.Move:Connect(function() game.ReplicatedStorage.RemoteEvent:FireServer(mouse.hit.X, mouse.hit.Y, mouse.hit.Z, part) end) end end)
Server script:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, x,y,z, part) part.Position = Vector3.new(x,y,z) end)
Thanks for help!!
Hello, Oficcer_F!
I have removed the tool.Equipped
because it was making the script don't run, I also made some other changes that are explained on the comments
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local down = false local tool = script.Parent mouse.Button1Down:Connect(function() if not game.Players:GetPlayerFromCharacter(script.Parent.Parent) then return end --Returns if parent is not player character(tool equiped) if not mouse.Target then return end --Returns if no mouse target(Moved) down = true part = mouse.Target end) mouse.Button1Up:Connect(function() --Un sets the bool 'down' and the var 'part' if not game.Players:GetPlayerFromCharacter(script.Parent.Parent) then return end --Returns if parent is not player character(tool equiped) down = false part = nil end) mouse.Move:Connect(function() if not game.Players:GetPlayerFromCharacter(script.Parent.Parent) then return end --Returns if parent is not player character(tool equiped) if not mouse.Target then return end --Returns if no mouse target(Moved) if down then--Moved this to test every mouse move game.ReplicatedStorage.RemoteEvent:FireServer(mouse.hit.X, mouse.hit.Y, mouse.hit.Z, part) end end)
You should also use a Remote Event
as your Remote Function
isn't returning any value
To make code easier to read, please ident it, thanks
Hope this helps
Good Luck with your games