DrawingJhon

Coin floating effect

Aug 7th, 2020 (edited)
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.43 KB | None | 0 0
  1. local model = Instance.new("Model", workspace)
  2. model.Name = "Coin"
  3. local hum = Instance.new("Humanoid", model)
  4. hum.Name = "NameTag"
  5. local coin = Instance.new("Part", model)
  6. coin.Anchored = false
  7. coin.Name = "Head"
  8. coin.Shape = "Cylinder"
  9. coin.Position = Vector3.new(0, 2.5, 0)
  10. coin.Size = Vector3.new(0.5, 3, 3)
  11. coin.CanCollide = false
  12. coin.BrickColor = BrickColor.new("Bright yellow")
  13. coin.TopSurface = "Smooth"
  14. coin.BottomSurface = "Smooth"
  15. local sound = Instance.new("Sound", coin)
  16. sound.SoundId = "rbxassetid://131323304"
  17. sound.EmitterSize = 5
  18. local bodypos = Instance.new("BodyPosition", coin)
  19. bodypos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  20. bodypos.Position = coin.Position
  21. local ang = Instance.new("BodyAngularVelocity", coin)
  22. ang.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
  23.  
  24. local db = false
  25. coin.Touched:Connect(function(hit)
  26.     local isPlayer = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
  27.     if not isPlayer or db then return end
  28.     db = true
  29.     sound:Play()
  30.     for i = 0, 1, 0.1 do
  31.         coin.Transparency = i
  32.         wait()
  33.     end
  34.     coin:Remove()
  35. end)
  36.  
  37. local firstP = coin.Position.Y
  38. local tw = game:GetService("TweenService")
  39. while true do
  40.     local info = TweenInfo.new(0.7)
  41.     local p = tw:Create(bodypos, info, {Position = Vector3.new(0, firstP + 0.5, 0)})
  42.     local p2 = tw:Create(bodypos, info, {Position = Vector3.new(0, firstP - 0.5, 0)})
  43.     p:Play()
  44.     wait(1)
  45.     p2:Play()
  46.     wait(1)
  47. end
Add Comment
Please, Sign In to add comment