Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Moving a brick with a tool?

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

4 comments

2

Calling :FireServer() from a LocalScript automatically passes an initial argument, being the player who called it. You should be catching (plr, x, y, z, part) even if you don't use plr.

0

Ok.

0

Still doesnt work.

0

indent ur code

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.