mouse.Button1Down not detecting?

Thank you for the suggestion but no, that doesn’t work either.

So does your script work without the UI, but doesn’t work with the UI?

Yes, that’s what’s happening… I do want the UI though so I’m going to try a keybind approach instead of a click or tool.activated.

I have tried something in studio, and so far I can see it tweening… However it looks like a rocket launcher, it only tweens the server in one direction.

Tool
LocalScript
Script
RemoteEvent

LocalScript

local tool = script.Parent
local userMouse = game.Players.LocalPlayer:GetMouse()

local remoteEvent = script.Parent:WaitForChild("RemoteEvent")
print("Found remote")

tool.Activated:Connect(function()
    remoteEvent:FireServer(userMouse.X, userMouse.Y)
end)

Script

local Event = script.Parent.RemoteEvent
	
Event.OnServerEvent:Connect(function(player, mouseX, mouseY)
	local targetPosition = Vector3.new(mouseX, mouseY, 10)
	local movingBlock = game.Workspace.Part:Clone()
	movingBlock.Parent = game.Workspace
	local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
	local tween = game.TweenService:Create(movingBlock, tweenInfo, {CFrame = CFrame.new(targetPosition)})
	tween:Play()
	tween.Completed:Connect(function()
		movingBlock:Destroy()
	end)
end)

RemoteEvent

"Place in the tool."

Found a solution, works perfectly with a UI on the screen.

LocalScript

local tool = script.Parent
local userMouse = game.Players.LocalPlayer:GetMouse()
local remoteEvent = script.Parent:WaitForChild("RemoteEvent")
print("Found remote")

tool.Activated:Connect(function()
	local hitPosition = userMouse.Hit.Position
	remoteEvent:FireServer(hitPosition.X, hitPosition.Y, hitPosition.Z)
end)

Script

local Event = script.Parent.RemoteEvent
	
Event.OnServerEvent:Connect(function(player, mouseX, mouseY, mouseZ)
	local targetPosition = Vector3.new(mouseX, mouseY, mouseZ)
	local movingBlock = game.Workspace.Part:Clone()
	movingBlock.Parent = game.Workspace
	local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
	local tween = game.TweenService:Create(movingBlock, tweenInfo, {CFrame = CFrame.new(targetPosition)})
	tween:Play()
	tween.Completed:Connect(function()
		movingBlock:Destroy()
	end)
end)

All of these go in the tool, as well as a remote event.

Here is a clip that shows how it works.

1 Like

It would’ve been nice to see this work for me! But unfortunately it doesn’t for whatever reason, I’ve gotten pretty close to what I want though! My issue now is this.
image

Local Script

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
local mouse = player:GetMouse()
local tweenserv = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(5)
local equipped = false
local UIS = game:GetService("UserInputService")

script.Parent.Equipped:Connect(function()
	equipped = true
	print("yes")
end)

script.Parent.Unequipped:Connect(function()
	equipped = false
	print("no")
end)

UIS.InputBegan:Connect(function(input, GPE)
	if GPE then return end
	if input.KeyCode == Enum.KeyCode.F then
		if equipped then
			script.Parent.SendIt:FireServer(mouse.Hit)
		end
	end
end)

Server Script

local TS = game:GetService("TweenService")
local TI = TweenInfo.new(5)

script.Parent.SendIt.OnServerEvent:Connect(function(player,hitpos)
	print(hitpos)
	script.Parent.Value.Value.ScriptPart.Script:Destroy()
	local tween = TS:Create(script.Parent.Value.Value.PrimaryPart,TI,{Cframe = CFrame.new(hitpos.Position)})
end)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local tweenserv = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(5)
local equipped = false
local UIS = game:GetService("UserInputService")

local tool = script.Parent

tool.Equipped:Connect(function()
    equipped = true
    print("yes")
end)

tool.Unequipped:Connect(function()
    equipped = false
    print("no")
end)

UIS.InputBegan:Connect(function(input, GPE)
    if GPE then return end
    if input.KeyCode == Enum.KeyCode.F then
        if equipped then
            tool.SendIt:FireServer(mouse.Hit)
        end
    end
end)

local TS = game:GetService("TweenService")
local TI = TweenInfo.new(5)

tool.SendIt.OnServerEvent:Connect(function(player, hitpos)
    print(hitpos)
    local targetPart = script.Parent.Value.Value.PrimaryPart
    targetPart.Anchored = true
    local tween = TS:Create(targetPart, TI, {CFrame = CFrame.new(hitpos.Position)})
    tween:Play()
    tween.Completed:Wait()
    targetPart.Anchored = false
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.