Couldn't locate the error

Hey! I’m trying to make a flashlight script but the inputs or the event or the script doesn’t work. Can anyone find the error?

Local Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local ToggleEvent = script:WaitForChild("ToggleEvent")
local Debounce = false

local function Activator()
    if not _G.CheckIfCan(Character, "Any") then
        Debounce = true
        ToggleEvent:FireServer(true)
        wait(0.5)
        Debounce = false
    end
end

delay(0.5, function()
    local Table = {
        Title = "Body Flashlight",
        Text = "Press 'J' to toggle.",
        Duration = 30,
        Button1 = "Close"
    }
    ReplicatedStorage.Events2.Notification:Fire(Table, "beep")
end)

UIS.InputBegan:Connect(function(Input)
    if Debounce then
        return 
    end
    if Input.KeyCode == Enum.KeyCode.J then
        Activator()
    end
end)```

Server Script
```lua
local Character = script.Parent.Parent
local Flashlight = script.Parent.Parent.BodyFlashlight_1.Parts.Torso.Model.LP1
local Parts = Flashlight.Parent.Parent.Parent
local RemoteEvent = script.Parent.ToggleEvent
local ToggleSound = Flashlight.ToggleSound
local EnabledV = script.Parent.EnabledV

local function Toggler(parameter)
    if parameter == true then
        Flashlight.A1.P1.Enabled = true
        Flashlight.From.SpotLight.Enabled = true
        Flashlight.Enabled = true
        
        EnabledV.Value = true
        
        Flashlight.Material = Enum.Material.Neon
        
        local dSG = Instance.new("BoolValue", Flashlight.From)
        dSG.Value = true
        
        ToggleSound:Play()
    else
        Flashlight.A1.P1.Enabled = false
        Flashlight.From.SpotLight.Enabled = false
        Flashlight.Enabled = false
        
        EnabledV.Value = false
        
        Flashlight.From.dSG:Destroy()
        
        ToggleSound:Play()
    end
end

RemoteEvent.OnServerEvent:Connect(Toggler)```

I don’t see any obvious errors in the code you provided. Here are a few things you can try to troubleshoot the issue:

  1. Make sure that the ToggleEvent remote event is correctly defined and is being correctly referenced in both the client and server scripts.
  2. Make sure that the Activator function is being called correctly when the player presses the ‘J’ key. You can add some print statements to the function to see if it is being called as expected.
  3. Check for any errors that may be thrown in the server script when the Toggler function is called. This could help identify any issues with the function or the objects it is interacting with.
  4. Make sure that the objects being referenced in the server script (e.g. Flashlight , Parts , etc.) exist and are correctly configured.
1 Like

Thanks a lot! Printing method worked out quite well.

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