local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid: Humanoid = character:WaitForChild("Humanoid")
local event = game.ReplicatedStorage.ThrownBlock
local mouse = player:GetMouse()
local userservice = game:GetService("UserInputService")
local animator: Animator = humanoid.Animator
local animas = tool.Animations
local anims = {
holding = animator:LoadAnimation(animas.Holding),
throwing = animator:LoadAnimation(animas.Throw)
}
local debounce = true
anims.throwing.Priority = Enum.AnimationPriority.Action4
tool.Equipped:Connect(function()
anims.holding:Play(.6)
end)
tool.Unequipped:Connect(function()
anims.holding:Stop()
end)
tool.Activated:Connect(function()
if not debounce then return end
debounce = false
anims.throwing:Play()
task.wait(.67)
event:FireServer(tool.Handle, mouse.Hit.Position)
tool:Destroy()
anims.holding:Stop()
end)
Server Script Manager:
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local newblocks = SS:WaitForChild("ThrowingBlocks"):GetChildren()
local throwevent = RS:WaitForChild("ThrownBlock")
local debris = game:GetService("Debris")
throwevent.OnServerEvent:Connect(function(player: Player ,holdingblockpos, newblock, mouseHit)
newblock = newblocks[1]:Clone()
newblock.Parent = workspace
newblock.Position = holdingblockpos.Position
newblock.Rotation = holdingblockpos.Rotation
local force = 50
local BodyVelocity = Instance.new("BodyVelocity", newblock)
BodyVelocity.MaxForce = Vector3.new(1, 1, 1) * 10000000;
BodyVelocity.Velocity = newblock.CFrame.LookVector * force;
debris:AddItem(BodyVelocity, 0.1)
end)
--(mouseHit - holdingblockpos.Position).Unit * force + Vector3.new(0,(force / 2),0)
My first suggestion in the localscript is to replace :GetService("Players") with just .Players since it’s easier to type and is faster to load.
Your localscript doesn’t use input service so you can remove this
Instead of creating the blocks and putting them into serverstorage, you can use Instance.new("BasePart") in the server script and set the properties directly in that script so you can save space in serverstorage and create blocks just by using the script. I would recommend making the block creation in a separate function used by the connection.
Here’s an example I made:
function makepart()
local part = Instance.new("BasePart")
part.Name = "block"
part.Size = Vector3.new(3,3,3)
part.Position = CFrame.new() -- whatever you want the position to be
part.BrickColor = BrickColor.new("Really red") -- whatever color you want
part.Parent = workspace
part.CanCollide = false
-- return the created block
return part
end
local newpart = makepart()
I’m not exactly sure how debris is supposed to be used in this, but I assume you use it to make the part fall after 0.1 seconds? If that’s the case then you can make the BodyVelocity point upward for about a second or two and then destroy the velocity, which will make the ball start falling using gravity.
Just to be clear, I don’t know the entire use of this since the explanation was kind of short, but I hope this helped
You don’t need debris, just use Instance:Destroy().
If each block has its own animation you can store them in serverstorage if you wish, however for the animations you should make a string attribute for each block and set it to its animation ID so the script can :GetAttribute() and load the ID from that string.