Hello (again)
I have a problem with my gun, I am tweening a bullet from the position of the barrel, to the mouse.Hit.p (mouse position). For some reason I cannot get it to tween because of the same old error "Unable to cast to Dictionary), I want to do this so I can make bullet trails and bullet whizzing.
The bullet doesn’t even show up for some reason… Here is my code, if you need me to shorten it for you then I will do that: (Both local script and serverscript)
Localscript:
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")
local tool = script.Parent
local equip = tool:WaitForChild("Handle"):WaitForChild("Equip")
local EAnim = char:WaitForChild("Humanoid").Animator:LoadAnimation(equip)
local idle = tool:WaitForChild("Handle"):WaitForChild("Idle")
local IAnim = char:WaitForChild("Humanoid").Animator:LoadAnimation(idle)
local fire = tool:WaitForChild("Handle"):WaitForChild("Shoot")
local FAnim = char:WaitForChild("Humanoid").Animator:LoadAnimation(fire)
local reload = tool:WaitForChild("Handle"):WaitForChild("Reload")
local RAnim = char:WaitForChild("Humanoid").Animator:LoadAnimation(reload)
local Ammo = tool.Ammunition
local debounce = true
local AnimationDebounce = true
local Mouse = plr:GetMouse()
local Looping = true
tool.Equipped:Connect(function()
EAnim:Play()
wait(1)
IAnim:Play()
EAnim:Stop()
Mouse.Button1Down:Connect(function(mouse)
if debounce and Ammo.Value > 0 then
Looping = true
while Looping do
if Ammo.Value <= 0 then
return
else
FAnim:Play()
Ammo.Value = Ammo.Value - 1
print(Ammo.Value)
tool.Handle.FSound:Play()
local mousepos = Mouse.Hit.p
tool.Fired:FireServer(mousepos)
wait(0.1)
debounce = true
end
end
elseif Ammo.Value <= 0 then
Looping = false
Ammo.Value = Ammo.Value
tool.Handle.out:Play()
end
end)
end)
Mouse.Button1Up:Connect(function()
Looping = false
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
if Ammo.Value >= 0 and AnimationDebounce == true then
AnimationDebounce = false
task.wait(0.3)
RAnim:Play()
tool.Handle.RSound:Play()
wait(2)
AnimationDebounce = true
Ammo.Value = 32
Looping = true
end
end
end)
tool.Unequipped:Connect(function()
wait()
IAnim:Stop()
FAnim:Stop()
repeat wait() until IAnim:Stop()
Looping = false
end)
Server:
local looping = true
local tool = script.Parent
local TweenService = game:GetService("TweenService")
local bullet = game.ServerStorage.Bullet
tool.Fired.OnServerEvent:Connect(function(plr, mouse)
local whiz = bullet:Clone()
whiz.Parent = game.Workspace
whiz.CFrame = CFrame.new(tool.RaycastPos.Position)
whiz.Touched:Connect(function(hit)
local char = plr.Character
local parent = tool.Parent
local hum = hit.Parent:FindFirstChild("Humanoid")
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= parent then
hum:TakeDamage(20)
end
whiz:Destroy()
end)
local tweeninfo = TweenInfo.new(
1,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false,
0
)
local goal = mouse
local Fired = TweenService:Create(whiz, tweeninfo, goal)
end)
I know using this is kinda weird but its what I was figuring out and what I came up to think of.
If you guys can help me that would be great.