Tool that make part follow mouse

  1. What do you want to achieve?
    I want to make tool that create part which can kill players.
    2.What is the issue?
  2. What solutions have you tried so far?
    Firstly im create Remote Event to set part position. Then i make script in ServerScriptService
local Remote = game.ReplicatedStorage:FindFirstChild("RemoteEvent")

if Remote then
	Remote.OnServerEvent:Connect(function(player, mouse)
		local part = Instance.new("Part",workspace)
		part.BrickColor = BrickColor.new("Bright red")
		part.CanCollide = true
		part.Touched:Connect(function(hit)
			if hit.Parent:FindfirstChild("Humanoid") then
				hit.Parent.Humanoid.Health = 0
			end
		end)
	end)
end

After that I make tool with local script
tool
And also script

local player = game.Players.LocalPlayer
local tool = script.Parent.Parent
local Remote = game.ReplicatedStorage:FindFirstChild("RemoteEvent")
local mouse = player:GetMouse()

if tool and Remote then
	tool.Equipped:Connect(function(part)
		part.Position = Vector3.new(mouse.Hit.Position.X,0.5, mouse.Hit.Position.Z)
		Remote:FireServer(part)
	end)
end

Can someone fix my script pls? Help pls

7 Likes

What is “part” defined in the function?

2 Likes

What sorry i dont understand your question?

1 Like

When you type function, inside the parenthesis, aka () there is “part.” This means it would be function(part). But, what does “part” mean?

2 Likes

I thought i will put part as parameter and tool will control part position

1 Like

Well, part isn’t defined anywhere in the script, so therefore nothing is being sent to the Remote.

1 Like

Ok. Also I’m update my server script

local Remote = game.ReplicatedStorage:FindFirstChild("RemoteEvent")

if Remote then
	Remote.OnServerEvent:Connect(function(player, mouse)
		local part = Instance.new("Part",workspace)
		part.BrickColor = BrickColor.new("Bright red")
		part.Position = Vector3.new(mouse.Hit.Position.X,0.5, mouse.Hit.Position.Z)
		part.CanCollide = true
		part.Touched:Connect(function(hit)
			if hit.Parent:FindfirstChild("Humanoid") then
				hit.Parent.Humanoid.Health = 0
			end
		end)
	end)
end

But there is new error
Hit is not a valid member of CFrame - Server
Stack Begin - Studio
Script ‘ServerScriptService.PartPosition’, Line 7 - Studio
Stack End - Studio

2 Likes

Local

local player = game.Players.LocalPlayer
local tool = script.Parent.Parent
local Remote = game.ReplicatedStorage:FindFirstChild("RemoteEvent")
local mouse = player:GetMouse()

if tool and Remote then
	tool.Equipped:Connect(function(part)
		Remote:FireServer(mouse.Hit)
	end)
end
1 Like

Update server script with this.

local Remote = game.ReplicatedStorage:FindFirstChild("RemoteEvent")

if Remote then
	Remote.OnServerEvent:Connect(function(player, mouseHit)
		local part = Instance.new("Part",workspace)
		part.BrickColor = BrickColor.new("Bright red")
		part.Position = Vector3.new(mouseHit.Position.X,0.5, mouseHit.Position.Z)
		part.CanCollide = true
		part.Touched:Connect(function(hit)
			if hit.Parent:FindfirstChild("Humanoid") then
				hit.Parent.Humanoid.Health = 0
			end
		end)
	end)
end
1 Like

There is problem

1 Like

Update server script with this. Should work this time.

local Remote = game.ReplicatedStorage:FindFirstChild("RemoteEvent")

if Remote then
	Remote.OnServerEvent:Connect(function(player, mouseHit)
		local part = Instance.new("Part",workspace)
		part.BrickColor = BrickColor.new("Bright red")
		part.Position = Vector3.new(mouseHit.Position.X,0.5, mouseHit.Position.Z)
		part.CanCollide = true
		part.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				hit.Parent.Humanoid.Health = 0
			end
		end)
	end)
end
1 Like

Ok its work but last thing how can i make move part like here

1 Like

I am not sure. Is it in a loop?

1 Like

No this is in local script

local mouse = game.Players.LocalPlayer:GetMouse()
local part = workspace.Part
mouse.Move:Connect(function()
part.Position = Vector3.new(mouse.Hit.Position.X,0.5, mouse.Hit.Position.Z)
end)
1 Like

So I add move function in server script

local Remote = game.ReplicatedStorage:FindFirstChild("RemoteEvent")

if Remote then
	Remote.OnServerEvent:Connect(function(player, mouseHit)
		local part = Instance.new("Part",workspace)
		part.BrickColor = BrickColor.new("Bright red")
		mouseHit.Move:Connect(function()
			part.Position = Vector3.new(mouseHit.Position.X,0.5, mouseHit.Position.Z)
		end)
		part.CanCollide = true
		part.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				hit.Parent.Humanoid.Health = 0
			end
		end)
	end)
end

And i have problem
Move is not a valid member of CFrame

1 Like

Move is not a valid member of CFrame - Server
Stack Begin - Studio
Script ‘ServerScriptService.PartPosition’, Line 7 - Studio
Stack End - Studio

1 Like

mouseHit is a CFrame. It is the mouse CFrame, not the players mouse.

1 Like
local Remote = game.ReplicatedStorage:FindFirstChild("RemoteEvent")

if Remote then
	Remote.OnServerEvent:Connect(function(player, mouseHit)
		local part = Instance.new("Part",workspace)
		part.BrickColor = BrickColor.new("Bright red")
		part.CanCollide = true
		part.Position = CFrame.new(mouseHit.Position.X,0.5, mouseHit.Position.Z)
		part.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				hit.Parent.Humanoid.Health = 0
			end
		end)
	end)
end

Unable to assign property Position. Vector3 expected, got CFrame - Server
Stack Begin - Studio
Script ‘ServerScriptService.PartPosition’, Line 8 - Studio
Stack End - Studio

2 Likes

instead of cframe, use vector3.

1 Like

Ok its working but i need that part follow my mouse

1 Like