I am trying to set up a basic gun base, for later development, but it isn’t doing damage to the dummy that i placed, both from behind and in front of a wall.
Everything works fine, value being changed when it needs to, and the sound is played. The only issue is damaging the dummy, and the Raytracing
The gun is this, and the green circle is the attachment
This is the setup for the testing
I tried changing the attachments, changing from attachment.CFrame.Position to Attachment.WorldCFrame.Position, and changing Raycast Parems
Here is the Client Side Script:
local player = game.Players.LocalPlayer
local tool = script.Parent
tool.Activated:Connect(function()
if tool.Parent == player.Character then
local mouse = player:GetMouse()
if mouse.Target then
script.Parent.Hit:FireServer(mouse.Hit.Position, mouse.Target)
end
end
end)
Here is the Server side script:
local event = script.Parent.Hit
local playerservice = game.Players
event.OnServerEvent:Connect(function(player, Cframe, target)
script.Parent.canfire.Value = false
local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Exclude
rayParams.FilterDescendantsInstances = {player.Character}
local origin = script.Parent.Handle.FirePoint.CFrame.Position
local result = game.Workspace:Raycast(origin, Cframe-origin, rayParams)
local distance = (origin - Cframe).Magnitude
if result ~= target then
script.Parent.Handle.Fire:Play()
wait(1.2)
script.Parent.canfire.Value = true
else
if playerservice:GetPlayerFromCharacter(target.Parent) then
if target.Name == "Head" then
script.Parent.Handle.Fire:Play()
target.Parent.Humanoid:TakeDamage(20)
wait(1.2)
script.Parent.canfire.Value = true
else
script.Parent.Handle.Fire:Play()
target.Parent.Humanoid:TakeDamage(5)
wait(1.2)
script.Parent.canfire.Value = true
end
else
script.Parent.Handle.Fire:Play()
wait(1.2)
script.Parent.canfire.Value = true
end
end
end)
Remote.OnServerEvent:Connect(function(Player: Player, Position: Vector3, OriginPosition: Vector3, IsShotgun: boolean, FireSound: Sound)
if Tool.Parent ~= Player.Character or Player.Character:FindFirstChildOfClass("ForceField") then return end
-- For gun shoot effect
--[[for _, Object in Tool.Handle.Barrel:GetChildren() do
if Object:IsA("ParticleEmitter") then
Object:Emit()
end
if Object:IsA("PointLight") then
Object.Enabled = true
task.delay(0.6, function()
Object.Enabled = false
end)
end
end]]
local Direction = (Position - OriginPosition).Unit
local Cast = BulletCaster:Fire(OriginPosition, Direction, GunData.Velocity/10, BulletBehavior)
Cast.RayInfo.CosmeticBulletObject:SetAttribute("Player", Player.Name)
FireSound:Play()
end)
Hi superglitchywilliam2, I think the direction parameter you put in is wrong, it should be done like this;
local result = game.Workspace:Raycast(origin, (Cframe.Position-origin).Unit, rayParams)
The entire script:
local event = script.Parent.Hit
local playerservice = game.Players
event.OnServerEvent:Connect(function(player, Cframe, target)
script.Parent.canfire.Value = false
local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Exclude
rayParams.FilterDescendantsInstances = {player.Character}
local origin = script.Parent.Handle.FirePoint.CFrame.Position
local result = game.Workspace:Raycast(origin, (Cframe.Position-origin).Unit, rayParams)
local distance = (origin - Cframe).Magnitude
if result ~= target then
script.Parent.Handle.Fire:Play()
wait(1.2)
script.Parent.canfire.Value = true
else
if playerservice:GetPlayerFromCharacter(target.Parent) then
if target.Name == "Head" then
script.Parent.Handle.Fire:Play()
target.Parent.Humanoid:TakeDamage(20)
wait(1.2)
script.Parent.canfire.Value = true
else
script.Parent.Handle.Fire:Play()
target.Parent.Humanoid:TakeDamage(5)
wait(1.2)
script.Parent.canfire.Value = true
end
else
script.Parent.Handle.Fire:Play()
wait(1.2)
script.Parent.canfire.Value = true
end
end
end)
Using the FastCast module is useful too, but hopefully this amendment alone should solve your current issue, let me know of any further problems.
I ended up figuring it out by using the handle instead of an attachment. Thanks for the suggestions though. FastCast looks great, but I don’t really think it’s for me.