. What do you want to achieve? Keep it simple and clear!’
- I want to make it where the position of my mouse on the other side of a wall the RayCast/Bullet will not go past it and stop where the wall is.
- My Bullets has a inf stud it only stops when there is a part that the mouse is hitting.
- When I shoot the sky the bullets don’t show.
-
What is the issue? Include screenshots / videos if possible!
I tired looking on Youtube, Devforum and non of it worked. I’m still Kind of knew to Raycast. If there anything else i can learn please tell me. Ty have a good one
here my script
–Client Side
local testEven = game.ReplicatedStorage.GunEvents.TestGun:WaitForChild("TestEvent")
local ShootEvent = game.ReplicatedStorage.GunEvents.TestGun:WaitForChild("ShootEvent")
local UIS = game:GetService("UserInputService")
local RepStorage = game:GetService("ReplicatedStorage")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild("Humanoid") or Character:WaitForChild("Humanoid")
local TweenService = game:GetService("TweenService")
local hold = Character:WaitForChild("Humanoid"):LoadAnimation(RepStorage.Animations.TestGun:WaitForChild("Zoom"))
local Shoot = Character:WaitForChild("Humanoid"):LoadAnimation(RepStorage.Animations.TestGun:WaitForChild("Shoot"))
local equiped = Character:WaitForChild("Humanoid"):LoadAnimation(RepStorage.Animations.TestGun:WaitForChild("Equipped"))
local Scope = script.Parent.Handle.Scope
local LaserPointer = script.Parent.Handle.LaserPoint.SpotLight
local GunSound = RepStorage.Sound.GunSund.TestGunSound.COM18_Suppressor
local beamSound = RepStorage.Sound.GunSund.TestGunSound.NightVision
local shoot = script.Parent.Handle.Shoot.Attachment
local cooldown = false
local Black = shoot.BlackSparks
local Circle = shoot.Circle
local Sparklies = shoot.Sparklies
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Enable = false
local on = false
local Cool = false
local debouce = false
script.Parent.Equipped:Connect(function()
if Enable == false then
Enable = true
equiped:Play()
Mouse.Icon = "rbxassetid://14344850185"
print("Equipped")
end
end)
script.Parent.Unequipped:Connect(function()
Enable = false
Mouse.Icon = "rbxasset://SystemCursors/Arrow"
hold:Stop()
print("Unequipped")
end)
UIS.InputBegan:Connect(function(input, p)
if Enable == true and not p and input.UserInputType == Enum.UserInputType.MouseButton2 then
if on == false then
on = true
Scope.Transparency = 0
LaserPointer.Enabled = true
Mouse.Icon = "rbxassetid://14344808579"
hold:Play()
print("Hold")
testEven:FireServer("Pressed")
end
end
end)
UIS.InputEnded:Connect(function(input, G)
if Enable == true and not G and input.UserInputType == Enum.UserInputType.MouseButton2 then
Scope.Transparency = 1
LaserPointer.Enabled = false
hold:Stop()
print("Released")
Mouse.Icon = "rbxassetid://14344850185"
testEven:FireServer("presed1")
on = false
end
end)
script.Parent.Activated:Connect(function()
if cooldown == false then
cooldown = true
Black:Emit(10)
Circle :Emit(10)
Sparklies:Emit(8)
GunSound:Play()
local Start = script.Parent.Handle.Shoot.Position
local Distance = Mouse.hit.Position
Shoot:Play()
Character:FindFirstChild("Humanoid")
Humanoid.WalkSpeed = 7
wait(0.1)
Humanoid.WalkSpeed = 16
ShootEvent:FireServer(Start, Distance)
cooldown = false
end
end)```
---Server Side
```wait()
local RepStorage = game:GetService("ReplicatedStorage")
local testEven = game.ReplicatedStorage.GunEvents.TestGun:WaitForChild("TestEvent")
local ShootEvent = game.ReplicatedStorage.GunEvents.TestGun:WaitForChild("ShootEvent")
local ServerStorage = game:GetService("ServerStorage")
local Ts = game:GetService("TweenService")
local Debris = game:GetService("Debris")
local Character = script.Parent:FindFirstAncestorOfClass("Character")
local ServerStorage = game:GetService("ServerStorage")
local shoot = script.Parent.Handle.Shoot.Attachment
local GunSound = RepStorage.Sound.GunSund.TestGunSound.COM18_Suppressor
local Scope = script.Parent.Handle.Scope
local LaserPointer = script.Parent.Handle.LaserPoint.SpotLight
local beamSound = RepStorage.Sound.GunSund.TestGunSound.NightVision
local Black = shoot.BlackSparks
local Circle = shoot.Circle
local Sparklies = shoot.Sparklies
local exclude = {}
testEven.OnServerEvent:Connect(function(player, Value1, Value2)
if Value1 == "Pressed" then
wait(0.2)
beamSound:Play()
print(Value1)
end
end)
local function Bullet(Start, Distance)
local center = Start + Distance/ 2
local direaction = Distance.Magnitude
local Bullet = Instance.new("Part")
Bullet.Parent = workspace
Bullet.Color = Color3.new(0, 0, 0)
Bullet.Material = 'Neon'
Bullet.Size = Vector3.new(0.1, 0.1, direaction)
Bullet.Anchored = true
Bullet.CanCollide = false
Bullet.CFrame = CFrame.new(center, Start)
Ts:Create(Bullet, TweenInfo.new(0.5), {Size = Vector3.new(0,0,direaction)}):Play()
Debris:AddItem(Bullet, 0.5)
return Bullet
end
ShootEvent.OnServerEvent:Connect(function(player, Start, End)
local Character = player.Character
local Distance = (End - Start)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {player.Character}
local ray = workspace:Raycast(Start, Distance.Unit * 300, params)
if ray then
print(ray)
local hit = ray.Instance
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
if ray.Instance.Name == "Head" then
Humanoid.Health -= 30
print("Head")
else
Humanoid.Health -= 10
print("Body")
end
end
end
Bullet(Start, Distance)
end)```