#Raycasting not working all the time
19 messages · Page 1 of 1 (latest)
alright
can i test the game to figure out whats going on
wym
So i can see why it isnt working
I can publish the game and send the link
k
alr 1 sec
kk
yea its hittign a humaniod
ok join back may have fixed it
k
** You are now Level 1! **
I cant upload a video, but when I shoot someone it dont always do damage, even if you are looking directly at them, any ideas on how to fix? here is code :gunscript (local): ```lua
local players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local player = players.LocalPlayer
local mouse = player:GetMouse()
local gun = script.Parent
local shot = rs:FindFirstChild("shot")
local dmg = gun:GetAttribute("damage")
mouse.Button1Down:Connect(function()
shot:FireServer(gun, gun.start.Position, mouse.Hit.Position)
end)
dmg script (global)
```lua
local rs = game:GetService("ReplicatedStorage")
local shot = rs:FindFirstChild("shot")
shot.OnServerEvent:Connect(function(plr, gun, start, stop)
local dir = stop - start
local raycast = workspace:Raycast(start, dir)
local dmg = gun:GetAttribute("damage")
if raycast then
local hit = raycast.Instance.Parent
local human = hit:FindFirstChild("Humanoid")
if human and hit.Name ~= plr.Name then
human.Health -= dmg
if human.Health == 0 then
plr.leaderstats.kills.Value += 1
human.Health = 100
end
end
end
end)
when "shooting" it will give nil in return even if its hitting a player