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

Laser Beam Projectile not working?

Asked by 3 years ago

Hello. I was working on a laser beam projectile. But for some odd reason, the Laser Beam has been acting weirdly. I will give the code:

Client Code:

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local UIS = game:GetService("UserInputService")
debounce = false
UIS.InputBegan:Connect(function(key, isTyping)
if key.KeyCode == Enum.KeyCode.L and isTyping == false then
        RemoteEvent:FireServer()
        debounce = true
        wait(5)
        debounce = false
end 
end)
UIS.TouchTapInWorld:Connect(function(isTyping)
    if isTyping == false then
        RemoteEvent:FireServer()
        debounce = true
        wait(5)
        debounce = false
    end
end)

and the Server Code:

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local Laser = game:GetService("ReplicatedStorage"):WaitForChild("LaserBeam")
RemoteEvent.OnServerEvent:Connect(function(player)
    print("Worked")
    local Clone = Laser:Clone()
    Clone.Anchored = true 
    Clone.Position = player.Character:WaitForChild("UpperTorso").Position + Vector3.new(0,0,5)
    player.Character:WaitForChild("HumanoidRootPart").Anchored = true
    Clone.Parent = workspace
    Clone.Orientation = player.Character:WaitForChild("Head").Position
    Clone.Touched:Connect(function(hit)
        if hit == player.Character and Laser.Position == player.Character.UpperTorso.Position then
            return 
        end
        if hit ~= player.Character then
            hit.Parent:WaitForChild("Humanoid").Health = hit.Parent:WaitForChild("Humanoid").Health - 15
        end
    end)
    wait(0.89)
    Clone:Destroy()
    player.Character:WaitForChild("HumanoidRootPart").Anchored = false
end)

Also, I got into scripting in 2020, so this script isnt perfect.

0
What do you mean by "been acting weirdly"? Are there any errors? Is the laser not positioned correctly? RoiGipot 1 — 3y
0
The orientation is not matching the players position/orientation. Finty_james 269 — 3y
0
Same as it is not doing dmg to nearby models that is possesing a humanoid. This is my problem. Finty_james 269 — 3y

Answer this question