Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't this framework script creating a ray?

This is a ray script for a viewmodel gun. It's supposed to make a bullet and deal 40 damage when a player is touched by it, but the ray is never created.

function createray()
	local ray = Ray.new(gun["AN-94"].Flash.CFrame.p (mouse.Hit.p - gun["AN-94"].Flash.CFrame.p) * s.range)
	local hit, position = workspace:FindPartOnRay(ray, char, false, true)
	
	local bullet = Instance.new("Part")
	bullet.Parent = workspace
	bullet.Material = Enum.Material.Neon
	bullet.Color = BrickColor.new("New Yeller")
	bullet.Anchored = false
	bullet.CanCollide = false
	bullet.CFrame = (mouse.Hit.p - gun["AN-94"].Flash.CFrame.p)
	local vel = Instance.new("BodyVelocity")
	vel.Parent = bullet
	
	game:GetService("Debris"):AddItem(bullet, 0.1)
	
		local human = hit.Parent:FindFirstChild("Humanoid")
		if human then 
			human:TakeDamage(40)
		
		end
	
end

this is just part of a bigger framework script.

1 answer

function createray()
    local ray = Ray.new(gun["AN-94"].Flash.CFrame.p (mouse.Hit.p - gun["AN-94"].Flash.CFrame.p) * s.range)
    local hit, position = workspace:FindPartOnRay(ray, char, false, true)

    local bullet = Instance.new("Part")
    bullet.Parent = workspace
    bullet.Material = Enum.Material.Neon
    bullet.Color = BrickColor.new("New Yeller")
    bullet.Anchored = false
    bullet.CanCollide = false
    bullet.CFrame = (mouse.Hit.p - gun["AN-94"].Flash.CFrame.p)
    local vel = Instance.new("BodyVelocity")
    vel.Parent = bullet

    game:GetService("Debris"):AddItem(bullet, 0.1)

        local human = hit.Parent:FindFirstChild("Humanoid")
        if human then 
            human:TakeDamage(40)

        end

end

createray() -- place this where ever

3 comments

0

This just broke the script

0

I mean, the viewmodel still attaches itself, but the gunshot sound doesn't play and the animations don't play

0

oh

This discussion is preserved as it was. New answers, comments, and votes are closed.