Isle like weapon system issue

  1. What do you want to achieve? Remaking an Isle like weapon system

  2. What is the issue? The framework works fine, but when you or the target is moving and you fire at it there’s a high chance it will break without any errors

  3. What solutions have you tried so far? No one has really has made isle guns successfully and talked about on devforum, so finding solutions is pretty hard, what’s even harder is, as I mentioned earlier, it just breaks without an error and I can’t seem to find a fix for it.

local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local Players = game:GetService("Players")

local Framework = ReplicatedStorage["Permafrost Framework"]
local Events = Framework.Events
local Modules = Framework.Modules

local WeaponEvents = Events.WeaponEvents

local NotificationSystem = require(Modules.NotificationSystem)
local CoreModule = require(Modules.CoreModule)
local Library = require(Modules.Library)

local Tool = script.Parent
local Equipped = false
local Target = nil
local Canfire = true

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local Controls = require(Player.PlayerScripts.PlayerModule):GetControls()

local UpperTorso = Character:WaitForChild("UpperTorso")
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
local Humanoid = Character:FindFirstChild("Humanoid")

local Waist = UpperTorso.Waist
local OriginalWaistC0 = Waist.C0

local Mouse = Player:GetMouse()

local TweenTime = 1
local tweenInfo = TweenInfo.new(TweenTime, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)

local Animations = Tool.Animations

Idle = CoreModule.PlayAnimation(Character, Tool.Name,  "Idle")
Fire = CoreModule.PlayAnimation(Character, Tool.Name, "Fire")
Reload = CoreModule.PlayAnimation(Character, Tool.Name, "Reload")

local function onEquipped()
	Idle:Play()
	Equipped = true
end

local function onUnequipped()
	Idle:Stop()
	Equipped = false
	Target = nil
end

local function getText(textIndex, target, caller)
	local text = Library:getText(textIndex, target, caller)
	return text
end

local function FireShot(Target)
	WeaponEvents.Fire:FireServer(Target, OriginalWaistC0, TweenTime, Tool)
	Fire:Play()
	task.wait()
	TweenService:Create(Waist, tweenInfo, { C0 = OriginalWaistC0 }):Play()
	Controls:Enable()
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
	Target = nil
end

local function Aim(TargetNPC)
	if Equipped and TargetNPC:IsA("Model") then
		Controls:Disable()
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
		local Info = getText(Tool.Name, Target, Player)
		NotificationSystem.addText(Player, Info["AimColor"], Info["AimText"])
		local Location = Vector3.new(Target.PrimaryPart.Position.X, UpperTorso.Position.Y, Target.PrimaryPart.Position.Z)
		
		local x,y,z = CFrame.new(HumanoidRootPart.Position, Target.UpperTorso.Position):ToOrientation()
		
		TweenService:Create(HumanoidRootPart, tweenInfo, { CFrame = CFrame.lookAt(HumanoidRootPart.Position, Location) }):Play()
		TweenService:Create(Waist, tweenInfo, { C0 = CFrame.new(Waist.C0.Position) * CFrame.Angles(x,0,0) }):Play()
		WeaponEvents.Aim:FireServer(x, TweenTime, Canfire)
    end
end


local function onClick()
	if not Canfire then return end
	Canfire = false
	local TargetNPC;
	if Mouse.Target.Parent:FindFirstChild("Humanoid") or Mouse.Target.Parent.Parent:FindFirstChild("Humanoid") then
		TargetNPC = Mouse.Target.Parent
		Target = TargetNPC
	else
		return
	end
	
	
	
	local Gun = Library.gunIds[Tool.Name]
	local Info = getText("General", TargetNPC, Player)
	if Equipped and TargetNPC:FindFirstChild("Humanoid") and TargetNPC.Humanoid.Health > 0 then

		local rayOrigin = Tool.Handle.Position
		local rayDirection = (TargetNPC.PrimaryPart.Position - Tool.Handle.Position).Unit
		local rayDistance = (TargetNPC.PrimaryPart.Position - Tool.Handle.Position).Magnitude
		
		local raycastParams = RaycastParams.new()
		raycastParams.FilterType = Enum.RaycastFilterType.Exclude
		raycastParams.FilterDescendantsInstances = { Character }

		local ray = Ray.new(Tool.Handle.Position, rayDirection*10000)  -- Change 100 to desired ray length
		local hitPart, hitPosition, hitNormal = workspace:FindPartOnRayWithIgnoreList(ray, {Character})
		if hitPart and hitPart:IsDescendantOf(Target) then
			Aim(Target)
			task.wait(2)

			if Equipped and Target == TargetNPC then
				FireShot(Target)
			end
		elseif rayDistance > Gun.Range then
			NotificationSystem.addText(Player, Info["AimColor"], Info["OutOfRangeText"])
		elseif Mouse.Target.Parent:FindFirstChild("Humanoid") and hitPart and not hitPart:IsDescendantOf(Target) then
			NotificationSystem.addText(Player, Info["AimColor"], Info["PathObstructedText"])
		end
		Canfire = true
	end
end

WeaponEvents.Fire.OnClientEvent:Connect(function(Target, Hit, HitShots)
	local Info = getText(Tool.Name, Target, Player)
	if Hit then
		NotificationSystem.addText(Player, Info["HitColor"], string.format(Info["HitText"], Target.Name), HitShots)
	else
		NotificationSystem.addText(Player, Info["MissedColor"], string.format(Info["MissedText"], Target.Name))
	end
end)

Tool.Equipped:Connect(onEquipped)
Tool.Unequipped:Connect(onUnequipped)
Tool.Activated:Connect(onClick)
2 Likes

Just have a bunch of print() statements and check if everything works in every scenario.

Sadly I already tried that. It just breaks outta nowhere.

it was a misplaced Canfire = true at the end of onClick function

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.