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

How do I make something point and "shoot" at the player?

Asked by 3 years ago
Edited 3 years ago

Hi! This is my first post on Scripting Helpers. Anyway, I will try my best to obey the rules in here, Sorry if I do something wrong.Also, I am new to I will try my best to explain. So basically, there is a Cannon, a Bridge, and a Fireball. When the player touches the Bridge (game.Workspace.Bridge), it will track the "position" of the player (The position of the UpperTorso). The Fireball (game.ServerStorage.Fireball), and the Cannon (game.Workspace.Cannon) are in the same position. Then the Fireball will point at the player. Then, it will create a copy of itself, with it's parent being game.Workspace. Then, it will go to "foward"(by foward, I mean into the positive X direction) relative to the original Fireball. The player will then attempt to dodge these fireballs. I will work out the whole explosion killing part later. The script is in ServerScriptService. The problem is, when I touch the Bridge part, my Roblox Studio will freeze and then crash. The code I used for this is below. I've tried to use ToWorldSpace and it does not work.

local cannon = game.Workspace.Cannon
local fireball = game.ServerStorage.Fireball
local bridge = game.Workspace.Bridge
local cPos = cannon.Position

while true do
    bridge.Touched:Connect(function(hit)
        if game.Players:GetPlayerFromCharacter(hit.Parent)then
            repeat
                local playerPos = hit.Parent.UpperTorso.Position
                fireball.CFrame = CFrame.new(cPos,playerPos)
                local fbCopy = fireball:Clone()
                fbCopy.Parent = game.Workspace
                fbCopy.Anchored = false
                fbCopy.Velocity = fireball.CFrame:PointToWorldSpace(50,0,0)
                wait(2)
            until bridge.TouchEnded:Connect(function(stop)
                fireball.CFrame = CFrame.new(cPos,playerPos)
                                stop = true
            end)
        end
    end)
end

Can someone help me please?

Answer this question