Hello Roblox Developers!
I have tried to make a throwable object which is a tool but failed. My original prototype used CFrame to keep it still and used velocity to move it. Eventually, there were lots of glitches such as this:
robloxapp-20230128-1922185.wmv (2.0 MB)
What Is it?
A dodgeball that players can throw but has a cooldown before they can throw it again
What is the task?
- Make a code that will use either (CFrame) or (Velocity)
What should it do?
- Only does damage to a player on a certain team
- Throw in the direction of the players click/tap
- When hit an effect will play (ball pop)
Specifics
- Ball will not be removed from a players inventory
- Ball will have a cooldown before it can be thrown again
Origanal Code:
local db = false
local directon
local Earnings = 50
local debris = game:GetService("Debris")
local Move = true
local Money = false
local Hit = 0
local Creator
script.Parent.PickenTarget.OnServerEvent:Connect(function(player,mouse)
directon = mouse
Creator = player
end)
script.Parent.Activated:Connect(function()
if not db then
db = true
-- Finds Positions
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
local WalkValue = humanoid.WalkSpeed
local possition1 = script.Parent.Handle.Position
local possition2 = directon
local Distance = math.abs((possition1 - possition2).Magnitude)
if Distance <= 10 then
else
-- Play the animation
local throwAnim = humanoid:LoadAnimation(script.Throw)
throwAnim:Play()
humanoid.WalkSpeed = 0
wait(.4)
-- Throws the ball
script.Parent.Handle.ThrowSound:Play()
script.Parent.Handle.Transparency = 1
local ball = script.Parent.Handle:Clone()
ball.Name = "DodgeBall"
ball.Parent = workspace
ball.Color = Color3.fromRGB(170,0, 0)
ball.Size = Vector3.new(3,3,3)
ball.Transparency = 0
ball.CanTouch = false
ball.CFrame = CFrame.new(script.Parent.Handle.Position + script.Parent.Handle.CFrame.LookVector * 3,directon)
local attachment0 = Instance.new("Attachment",ball); attachment0.Position = Vector3.new(-.5,0,0); attachment0.Orientation = Vector3.new(0,180,0)
local attachment1 = Instance.new("Attachment",ball); attachment1.Position = Vector3.new(.5,0,0)
local trail = Instance.new("Trail",ball); trail.Attachment0 = attachment0; trail.Attachment1 = attachment1
local bv = Instance.new("BodyVelocity",ball)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.P = 3000
delay(0.1, function()
ball.CanTouch = true
end)
local ori = 0
spawn(function()
while Move == true and wait() do
ori = ori - .05
ball.CFrame = ball.CFrame + ball.CFrame.lookVector * 6
ball.Orientation = Vector3.new(ball.Orientation.X + ori,ball.Orientation.Y, ball.Orientation.Z)
end
end)
-- When a ball touch something
local RedTeam = game.Teams["Blue Team"]
ball.Touched:Connect(function(hit)
ball.Transparency = 1
Move = false
ball.CanTouch = false
ball.Anchored = true
ball.BodyVelocity:Destroy()
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and player.Team == RedTeam then
local Hiddenleaderstats = Creator.Hiddenleaderstats
if Hiddenleaderstats.x2Gamepass.Value == true then
Creator.Hiddenleaderstats.Coins.Value += Earnings * 2
end
if Hiddenleaderstats.x2Gamepass.Value == false then
Creator.Hiddenleaderstats.Coins.Value += Earnings
end
if Hiddenleaderstats.x2XP.Value == true then
--Creator.Stats.Experience.Value += 25 * 2
end
if Hiddenleaderstats.x2XP.Value == false then
--Creator.Stats.Experience.Value += 25
end
local char = player.Character
local humanoid = char:FindFirstChild("Humanoid")
humanoid.Health = humanoid.Health -25
local hitSFX = Instance.new("Sound"); hitSFX.SoundId = "rbxassetid://9117969892"
hitSFX.Parent = ball
hitSFX:Play()
end
local Effect = script.Parent.Handle.Impact:Clone()
Effect.Parent = ball
Effect.Enabled = true
wait(0.1)
Effect.Enabled = false
wait(1)
ball:Destroy()
Move = true
Hit = 1
end)
-- Reloading the ball
humanoid.WalkSpeed = WalkValue
repeat
wait()
until Hit == 1
Hit = 0
script.Parent.Handle.Transparency = 0
db = false
end
end
end)
Please Help…