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

Why won't this mesh rotate? and why does the instance spawn ABOVE the forcefield?

Asked by 8 years ago

I am creating a forcefield tool and i'm still tweaking all of the parts, but i'm stumped at a part. Whenever this mesh spawns, the object doesn't rotate continually like i want it to. Also, when the mesh spawns, it spawns above the Force Field instead of inside it, next to the humanoid like I want it too. I'm assuming that's a collision issue, but i still don't know how to fix it. Here is the code:

local tool = script.Parent

local health = false

x = math.random(25, 50)
y = math.random(25, 50)

a = 0

b = 0

local debounce = false

local character = game:GetService('Players').LocalPlayer
local player = character.Character or character.CharacterAdded:wait()

tool.Equipped:connect(function(mouse)
    mouse.KeyDown:connect(function(key)
        if key == "q" and debounce == false then
    debounce = true
    print("ForceField")
    local ForceField = Instance.new("Part", player)
    ForceField.BrickColor = BrickColor.new("Deep blue")
    ForceField.Transparency = 0.7
    ForceField.CanCollide = false
    ForceField.Anchored = true
    ForceField.Shape = Enum.PartType.Ball
    ForceField.Size = Vector3.new(25,25,25)
    ForceField.BottomSurface = Enum.SurfaceType.Smooth
    ForceField.TopSurface = Enum.SurfaceType.Smooth
    ForceField.Position = player.Torso.Position
    ForceField.Parent = game.Workspace

    ForceField.Touched:connect(function(hit)
        local humanoid = hit.Parent:findFirstChild("Humanoid")
        if not hit:IsDescendantOf(player) and health == false then
            health = true
            humanoid.Health = humanoid.Health -3
            print ("DEATH TO THE HEATHENS")
            health = false
        else
            print("Hi Me ;)")
        end
    end)
    tool.Equipped:connect(function(mouse)
    mouse.KeyDown:connect(function(key)
        if key == "q" and debounce == false then
    local explosion = Instance.new("Part", player)
    local m = Instance.new("SpecialMesh")
    m.Parent = explosion
    m.MeshType = "FileMesh"
    m.MeshId = "http://www.roblox.com/asset/?id=20329976"
    m.TextureId = "http://www.roblox.com/asset?id=39251676"
    m.Scale = Vector3.new(8,8,8)
    explosion.Size = Vector3.new(8,8,8)
    explosion.Anchored = true
    explosion.CanCollide = false
    explosion.Transparency = 0
    repeat
        explosion.Rotation = Vector3.new(0,a,0)
        wait(.1)
        a = a+3
    until
    b == 0
    explosion.Position = player.Torso.Position
    explosion.Parent = game.Workspace
    wait(2)
    explosion:remove()

end
end)
end)
    wait(2)
    ForceField:remove()
    debounce = false
    end
end)
end)

it's quite a lot of code, but it's just spawning two different parts next to your character and damages anyone else that touches it, lol. Thanks in advance!

0
I also now realize, looking at my code as a whole that at the end, the until statement also contains the explosion.position so it's repeating until it's at the position, so i tried putting an end statement at the end of the until, but that still doesn't work :/ Sparkflyer34 40 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

When you set a part's position, it will not allow the part to clip through other parts, so it will automatically move it upwards and reset the rotation until it's not clipping any other parts.

The way to get around this would be to use CFrame

You will need to do something along these lines:

Part.CFrame = CFrame.new(
    XPosition,
    YPosition,
    ZPosition
) *CFrame.Angles(
    math.rad(XRotation),
    math.rad(YRotation),
    math.rad(ZRotation)
)

Here is an article on CFraming if you wish to read up on it more.

Hope this helps!

Ad

Answer this question