How can I fix this script and make it more efficient?

Hello! I am trying to make a script where the player can pick up a “puddle of water” by holding Q, being able to move it around (like some sort of telekinesis), and then dropping it. When you pick up the water puddle, it turns into a ball, and when you drop it, it turns back into a puddle.

I have a lot of issues with this script. First of all, the ball of water goes through the baseplate even though CanCollide is off. Second of all, dropping the ball doesn’t work properly (the physics are weird, I will post a video below). Third, when you drop one a puddle and then use the ability on another puddle, both puddles will be affected by the ability for some reason.

Here’s the video:

Here’s the scripts:

--local script
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if mouse.target and mouse.target:FindFirstChild("PropValue") and mouse.target.PropValue.Value == 1 and input.KeyCode == Enum.KeyCode.Q then --the puddles have a PropValue in them which determines the state of aggregation of the puddle 
		if debounce3 == false then
			debounce3 = true
			hydroremote1:FireServer(mouse.Target, mouse.Hit)
			while debounce3 == true do
				wait()
				mouseremote:FireServer(mouse.hit)
			end
		end
	end
	UserInputService.InputEnded:Connect(function(input, gameProcessedEvent)
		if input.KeyCode == Enum.KeyCode.Q then
			debounce3 = false
			wait()
		hydroremote2:FireServer()
		end
	end)
	end)

--server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remote = ReplicatedStorage.HydroRemote
local TweenService = game:GetService("TweenService")
local module = require(game:GetService("ServerScriptService"):WaitForChild("Hydro1"))

remote.OnServerEvent:Connect(function(player, target, hit)
	module.hydro1ab(player, target, hit)
		end)

--module script
local hydro1 = {}
local TweenService = game:GetService("TweenService")

function hydro1.hydro1ab(player, target, hit)
	local mouseremote = game:GetService("ReplicatedStorage").MouseRemote
	local humanoid = player.Character.Humanoid
	local animation = Instance.new("Animation")
	animation.AnimationId = "rbxassetid://5709116998"
	local animationTrack = humanoid:LoadAnimation(animation)
	animationTrack:Play()
	local hydroremote = game:GetService("ReplicatedStorage").HydroRemote0

	animationTrack:GetMarkerReachedSignal("Pause"):Connect(function(Pause)
		if Pause then
			animationTrack:AdjustSpeed(0)
		end

	end) --anim func end
	target.Anchored = true
	local Info = TweenInfo.new(
		0.1,
		Enum.EasingStyle.Bounce,
		Enum.EasingDirection.InOut,
		0,
		false,
		0
	)
	local goals = {}
	goals.Size = Vector3.new(1.46, 1.45, 2.39)
	local hydrotween = TweenService:Create(target, Info, goals)
	hydrotween:Play()
	
	mouseremote.OnServerEvent:Connect(function(player, hit)
	
	
		local Info1 = TweenInfo.new(
			0.4,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.InOut,
			0,
			false,
			0
		)
		local goals1 = {}
		goals1.Size = Vector3.new(2.26, 1.86, 2.77)
		goals1.Position = player.Character.Head.Position + (hit.Position - player.Character.Head.Position).unit * 20
		local hydrotween1 = TweenService:Create(target, Info1, goals1)
		
			hydrotween1:Play()

		
		
		
		end)
	
	hydroremote.OnServerEvent:connect(function()
		target.Anchored = false
		
		target.Touched:connect(function(thing)
			
			if thing.Parent:FindFirstChild("Humanoid") then
				target:Destroy()				
			end
			
			target.Size = Vector3.new(5.13, 4.78, 0.05)
		end)
		target:SetNetworkOwner(nil)
	end)
	
	end

return hydro1

I would really appreciate it if you guys could help me fix the existing issues, and also help me make the script more efficient altogether! I also have an example of how the end result should look like and I’ll post it if needed! Thank you!

1 Like

Maybe check out this community tutorial which may help with your issue

2 Likes

Thank you so so much! This is exactly what I was looking for!!!