Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Bubble Teleports Above Ground?

Asked by 6 years ago

I've been designing a bubble script for a game that goes in front of your head and increases in size and damage based on a stat, and it increases faster based on a speed stat. However, it seems to hover over the ground instead of next to your head. I assume this is because it resizes faster than it cframes it in front of your player, but honestly I have no idea.

Here's the code:

local tool = script.Parent
local name = game.ReplicatedStorage:FindFirstChild("NameVal").Value
local player = game.Players:FindFirstChild(name)
local char = game.Workspace:WaitForChild(name)
local head = char.Head
local touchhit = script.TouchHit
local bubblegum = Instance.new("Part")
touchhit.Parent = bubblegum
bubblegum.Transparency = 0.4
bubblegum.CanCollide = false
bubblegum.Size = Vector3.new(1, 2, 2)
bubblegum.Shape = "Ball"
bubblegum.BrickColor = BrickColor.new("Carnation pink")
bubblegum.BackSurface = "Smooth"
bubblegum.BottomSurface = "Smooth"
bubblegum.FrontSurface = "Smooth"
bubblegum.LeftSurface = "Smooth"
bubblegum.RightSurface = "Smooth"
bubblegum.TopSurface = "Smooth"
bubblegum.Anchored = true

function onUsed()
    script.Parent.Enabled = false
    local thing = 1
    local size = player.Stats.Size.Value
    local speed = player.Stats.Speed.Value
    local clone = bubblegum:clone()
    clone.Parent = game.Workspace
    spawn(function (follow)
        repeat
            coroutine.yield()
            clone.CFrame = head.CFrame + head.CFrame.lookVector * thing
        until done == true
    end)
    for i=1, size do
        clone.Orientation = head.Orientation + Vector3.new(0, 90, 0)
        clone.Size = clone.Size + Vector3.new(1, 1, 1)
        thing = thing + 0.5
        wait(1 - (speed / 100))
    end
    done = true
    clone:remove()
    done = false
    script.Parent.Enabled = true
end

function onActivated()
    if not tool.Enabled then
        return
    end
    tool.Enabled = false
    onUsed()
end

script.Parent.Activated:connect(onActivated)

Here's a video of what happens (I increased my size and speed a lot to make it more noticeable): https://www.youtube.com/watch?v=EeT1wBio7co

1 answer

Log in to vote
0
Answered by
JJ_B 250 Moderation Voter
6 years ago

When you change the size of a part it moves the part if it collides with another part. To fix this you need to reset the CFrame back in front of your head immediately after changing the size.

0
I tried to mess around a bit and I tried to make it so whenever the part changed it'd connect to another function that cframed it infront of your head, but I could never get the script to find the right clone the player was blowing. I tried making the clone named Bubblegum and using WaitForChild("Bubblegum"), and FindFirstChild("Bubblegum") but neither worked. Hamrhed2 4 — 6y
0
You can use the variable bubblegum you made. hiimgoodpack 2009 — 6y
0
But it's a local inside a function, and I have to call to it in another function. Do I make it a global? Hamrhed2 4 — 6y
Ad

Answer this question