I am making a game called EverRealm. It’s a fantasy RPG set in the medieval era. I’ve been creating & scripting weapons for this game such as swords, spears, and a bow and arrow. I got the swords and spears scripted okay, but I’m having a little trouble with the bow. I found a module called FastCast, which makes Raycasting much easier. I read the API docs for this and got to work. This is my script:
-- client
local tool = script.Parent
local player: Player = game.Players.LocalPlayer
local character: Model = player.CharacterAdded:Wait()
repeat wait() until character:IsDescendantOf(workspace);
local human: Humanoid = character:FindFirstChild("Humanoid")
local animator: Animator = human:FindFirstChild("Animator")
local equip: AnimationTrack = animator:LoadAnimation(tool:FindFirstChild("Equip"))
local unequip: AnimationTrack = animator:LoadAnimation(tool:FindFirstChild("Unequip"))
local shoot: AnimationTrack = animator:LoadAnimation(tool:FindFirstChild("Shoot"))
--local mouse = player:GetMouse();
local remotes = game.ReplicatedStorage.Remotes
local fire = remotes.BowFire
equip.Priority = Enum.AnimationPriority.Action4
unequip.Priority = Enum.AnimationPriority.Action4
shoot.Priority = Enum.AnimationPriority.Action4
equip.Looped = true
local Mouse = nil;
tool.Equipped:Connect(function(mouse)
equip:Play()
equip:AdjustSpeed(.1)
Mouse = mouse
end)
tool.Activated:Connect(function()
shoot:Play()
shoot:AdjustSpeed(.7);
task.wait(1.5);
--local mouse = player:GetMouse()
fire:FireServer(Mouse.Hit.Position)
end)
tool.Unequipped:Connect(function()
shoot:Stop()
equip:Stop()
unequip:Play()
unequip:AdjustSpeed(.1)
end)
-- server
cremotes.BowFire.OnServerEvent:Connect(function(player, direction)
local caster = casters[player.UserId]
local character: Model = player.Character;
--caster.VisualizeCasts = true
local tool = character:FindFirstChildWhichIsA("Tool")
if not tool then return end;
local typ: StringValue | nil = tool:FindFirstChild("ToolType");
if typ then
if typ.Value:lower() ~= "bow" then
return
end
end
local behavior = FastCast.newBehavior()
behavior.RaycastParams = RaycastParams.new()
behavior.RaycastParams.IgnoreWater = true
behavior.MaxDistance = 4500
behavior.RaycastParams.FilterDescendantsInstances = { character, tool }
local direction = CFrame.new(direction).LookVector
--local head: Part = character.Head
local firePoint: Attachment = tool.Handle:FindFirstChildWhichIsA("Attachment");
local speed = (direction * 30)
local cast = caster:Fire(firePoint.WorldPosition, direction, speed, behavior);
print(cast);
end)
I read the code for the example gun, and based my script off of it. I have tweaked this script many times, and it still will not work. Can somebody help me?