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

Moving a brick with a tool?

Asked by
Oficcer_F 207 Moderation Voter
5 years ago
Edited 5 years ago

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

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. SummerEquinox 643 — 5y
0
Ok. Oficcer_F 207 — 5y
0
Still doesnt work. Oficcer_F 207 — 5y
0
indent ur code User#23365 30 — 5y

1 answer

Log in to vote
1
Answered by
Leamir 3138 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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

Ad

Answer this question