#Tools break outside of Roblox Studios

12 messages · Page 1 of 1 (latest)

ruby apex
#

Server Script

local FastCast = require(game.ServerStorage:WaitForChild("Modules"):WaitForChild("FastCastRedux"))
local CastEvent = script.Parent:WaitForChild("CastEvent")
local CastParams = RaycastParams.new()
local BulletCache = game.Workspace:WaitForChild("BulletCache")
local BulletPart = game.ServerStorage:WaitForChild("Projectiles"):WaitForChild("Bullet")
local ShootPoint = script.Parent:WaitForChild("ShootPoint")
local BulletSpeed = 800
local MuzzleParticle = script.Parent.Parent:WaitForChild("MuzzleFlash"):WaitForChild("FlashParticle")
local MuzzleLight = script.Parent.Parent:WaitForChild("MuzzleFlash"):WaitForChild("FlashLight")

local function OnLengthChanged(cast, lastPoint, direction, length, velocity, bullet)
    if bullet then
        local bulletLength = bullet.Size.Z/2
        local offset = CFrame.new(0,0, (length - bulletLength))
        bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
    end
end

local Caster = FastCast.new()
local CasterBehavior = FastCast.newBehavior()
CasterBehavior.RaycastParams = CastParams
CasterBehavior.Acceleration = Vector3.new(0,0,0)
CasterBehavior.AutoIgnoreContainer = false
CasterBehavior.CosmeticBulletContainer = BulletCache
CasterBehavior.CosmeticBulletTemplate = BulletPart

CastEvent.OnServerEvent:Connect(function(Player, MouseHit)
    local Direction = (ShootPoint.WorldCFrame.Position - MouseHit).Unit
    Caster:Fire(ShootPoint.WorldCFrame.Position,MouseHit, BulletSpeed, CasterBehavior)
    MuzzleParticle:Emit(3)
    MuzzleLight.Enabled = true
    task.wait(0.035)
    MuzzleLight.Enabled = false
end)

Caster.RayHit:Connect(function(cast, result, velocity, bullet)
    local hit = result.Instance

    if hit.Parent:FindFirstChild("Humanoid") then
        print("hit a player")
        hit.Parent:FindFirstChild("Humanoid"):TakeDamage(25)
    end

    bullet:Destroy()
end)

Caster.LengthChanged:Connect(OnLengthChanged)
#

Local Script:

local TS = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local Run = game:GetService("RunService")
local Player = game:GetService("Players").LocalPlayer
local Tool = script.Parent.Parent
local Cam = game.Workspace.CurrentCamera
local OriginalFOV = Cam.FieldOfView
local AimFOV = OriginalFOV - 20
local Character = Player.Character
local RootPart = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")
local isAiming = false
local Mouse = Player:GetMouse()
local Crosshair = Player:WaitForChild("PlayerGui"):WaitForChild("CrosshairUI"):WaitForChild("CrosshairContainer")

local isEquipped = false
local isFullAuto = true
local isShooting = false
local OriginalZoom = Player.CameraMaxZoomDistance

local AnimationDir = script.Parent:WaitForChild("Animations")

local HoldingAnim =Humanoid:LoadAnimation(AnimationDir:FindFirstChild("Hold"))
HoldingAnim.Looped = true
HoldingAnim.Priority = Enum.AnimationPriority.Action

local AimingAnim = Humanoid:LoadAnimation(AnimationDir:FindFirstChild("Aim"))
AimingAnim.Looped = true
AimingAnim.Priority = Enum.AnimationPriority.Action2

local ShootAnim = Humanoid:LoadAnimation(AnimationDir:FindFirstChild("Shoot"))
ShootAnim.Looped = false
ShootAnim.Priority = Enum.AnimationPriority.Action3

local ReloadAnim = Humanoid:LoadAnimation(AnimationDir:FindFirstChild("Reload"))
ReloadAnim.Looped = false
ReloadAnim.Priority = Enum.AnimationPriority.Action4

local EquipAnim = Humanoid:LoadAnimation(AnimationDir:FindFirstChild("Equip"))
EquipAnim.Looped = false
EquipAnim.Priority = Enum.AnimationPriority.Action

local ZoomInfo = TweenInfo.new(0.25, Enum.EasingStyle.Sine)
local OffsetTween = TS:Create(Humanoid, ZoomInfo, {CameraOffset = Vector3.new(2,0,0)})
local OffsetReset = TS:Create(Humanoid, ZoomInfo, {CameraOffset = Vector3.new(0,0,0)})
local FOVTween = TS:Create(Cam, ZoomInfo, {FieldOfView = AimFOV})
#
local FOVReset = TS:Create(Cam, ZoomInfo, {FieldOfView = OriginalFOV})
local ZoomTween = TS:Create(Player, ZoomInfo, {CameraMaxZoomDistance = Player.CameraMinZoomDistance})
local ZoomReset = TS:Create(Player, ZoomInfo, {CameraMaxZoomDistance = OriginalZoom})

local ShootSound = script.Parent:WaitForChild("Sounds"):WaitForChild("ShootSound")
local EquipSound = script.Parent:WaitForChild("Sounds"):WaitForChild("EquipSound")

local CastEvent = nil
local SoundEvent = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("SoundEvent")

local function ToolEquipped()
    SoundEvent:FireServer(EquipSound)
    EquipAnim:Play()
    EquipAnim.Stopped:Wait()
    isEquipped = true
    HoldingAnim:Play()
    CastEvent = script.Parent:FindFirstChild("CastEvent")
end

local function Aim()
    isAiming = true
    UserSettings().GameSettings.RotationType = Enum.RotationType.CameraRelative
    HoldingAnim:Stop()
    Crosshair.Visible = true
    OffsetTween:Play()
    ZoomTween:Play()
    FOVTween:Play()
    AimingAnim:Play()
    UIS.MouseIconEnabled = false
    UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
    task.wait()
    Crosshair.Position = UDim2.new(0,Mouse.X,0,Mouse.Y)
end

local function Unaim()
    isAiming = false
    UserSettings().GameSettings.RotationType = Enum.RotationType.MovementRelative
    AimingAnim:Stop()
    Crosshair.Visible = false
    UIS.MouseBehavior = Enum.MouseBehavior.Default
    OffsetReset:Play()
    ZoomReset:Play()
    FOVReset:Play()
    HoldingAnim:Play()
    UIS.MouseBehavior = Enum.MouseBehavior.Default
    UIS.MouseIconEnabled = true
end

local function Shoot()
    while isShooting and isFullAuto do
        CastEvent:FireServer(Cam.CFrame.LookVector)
        SoundEvent:FireServer(ShootSound)
        ShootAnim:Play()
        task.wait(0.25)
    end
end```
round vergeBOT
#

studio** You are now Level 2! **studio

ruby apex
#
local function ToolUnequipped()
    isEquipped = false
    if HoldingAnim.IsPlaying then
        HoldingAnim:Stop()
    elseif AimingAnim.IsPlaying then
        AimingAnim:Stop()
    end
    if isAiming then
        isAiming = false
        Unaim()
    end
    CastEvent = nil
end

Tool.Activated:Connect(function()
    print("Is Activated")
    if isAiming then
        isShooting = true
        Shoot()
    end
end)

Tool.Deactivated:Connect(function()
    if isAiming then
        isShooting = false
    end
end)

UIS.InputBegan:Connect(function(input, gpe)
    if not gpe then
        if isEquipped then
            if input.UserInputType == Enum.UserInputType.MouseButton2 then
                Aim()
            end
        end
    end
end)

UIS.InputEnded:Connect(function(input, gpe)
    if not gpe then
        if isEquipped then
            if input.UserInputType == Enum.UserInputType.MouseButton2 then
                Unaim()
            end
        end
    end
end)

Tool.Unequipped:Connect(ToolUnequipped)
Tool.Equipped:Connect(ToolEquipped)```
#

sorry I had to divided the local script into multiple messages

#

(These are the scripts for 1 of the tools btw, not both)

torn lintel
#

Do you have both client and server access to the f9 console in the game?

#

You should send any logs/errors sent by both outside of studio if it doesn’t work

ruby apex
#

yeah I've been checking the console logs in game

#

no errors or anything, no infinite yields, right now im testing out the code at different points through print statements and checking where it stops

#

ok I'm starting to find the problem, its when I initially try to play an animation on equip