Hello developers! I was searching around for help on a gun and Ki1l3rBanana gave me a small tutorial on how to create a Ray Casting Gun. I followed the directions to the point. (As for as I know of.) But when I finished, it didn’t seem to work. Would you mind helping me figure out what I did wrong?
I have 2 scripts that I was told to put in. One was a LocalScript
called Player
and anouther was a ServerScript
called Server
. Both of these scripts are inside of a tool called Fifle. There is also a RemoteEvent
called PewPew
.
This one is the LocalScript
, called Player
:
local Gun = script.Parent
local PEWPEW = Gun:WaitForChild('PewPew')
local players = game:GetService('Players')
local localPlayer = players.LocalPlayer
local Mouse = localPlayer:GetMouse()
function callserver()
PEWPEW:FireServer(Mouse.Hit.Position)
end
Gun.Activated:Connect(callserver)
This one is the ServerScript
, called Server
:
local Gun = script.Parent
local muzzle = Gun:WaitForChild('Muzle')
local pewpew = Gun:WaitForChild("PewPew")
local Workspace = game:GetService("Workspace")
local ServerStorage = game:GetService("ServerStorage")
pewpew.OnServerEvent:Connect(function(plaer,position)
local origin = muzzle.Position
local direction = (position - origin).Unit*360
local result = Workspace:Raycast(origin,direction)
local HIT = result and result.Position or origin + direction
local distance = (origin - HIT).Magnitude
local CloneBullet = ServerStorage.Bullet:Clone()
CloneBullet.Size = Vector3.new(.1,.1,distance)
CloneBullet.CFrame = CFrame.new(origin,HIT)=CFrame.new(0,0-distance/2)
CloneBullet.Parent = Workspace
if result then
local part = result.Instance
local humanoid = part.Parent:FindFirstChild("Humanoid") or part.Parent.Parent:FindFirstChild:("Humanoid")
if humanoid then
humanoid:TakeDamage(25)
end else
return
end
wait(.25)
CloneBullet:Destroy()
end)
That is all. If anyone can help me out I would really appreciate it.