#Bindable events working on studio but not in game.

1 messages · Page 1 of 1 (latest)

lime quartz
#

I copied a smooth shiftlock script from the internet which uses bindable events.
Even though the script works in studio, the bindable event doesn't fire when I publish the game.

Local script (tool):

local ShiftLockEvent = rep.b_ToggleShiftLock
local function onEquipped()
    if not tool then return end
    ShiftLockEvent:Fire(true, aimDownsightsOffset, v_crosshair)
end

Local module script: (smooth Shiftlock):

local ToggleEvent = rep.b_ToggleShiftLock
function SmoothShiftLock:CharacterAdded()
  --// Bindables
  self.connectionsMaid:GiveTask(ToggleEvent.Event:Connect(function(toggle, offset, mouseIcon)
      if (self.Humanoid and self.Humanoid.Health ~= 0) then
          self:ToggleShiftLock(toggle, offset, mouseIcon);
      end;
  end));
  return self;
end;

I don't have much experience with oop so any help would be appreciated.
I also tested the same bindable event at the very beginning to a test function (not connected to the class) and it was working fine so I guess the problem is in the 2nd script.

#

I can provide the full script if needed

harsh rampart
#

@lime quartz

lime quartz
#

what should I do

agile nightBOT
#

studio** You are now Level 3! **studio

harsh rampart
# lime quartz what should I do

The issue is that BindableEvents only work within the same script context, so they break when you publish since the architecture separates everything properly. In your case, both scripts are client-side, so instead of using a BindableEvent, you should just directly call a function from the ModuleScript. For example, define a SmoothShiftLock:ToggleShiftLock(toggle, offset, mouseIcon) function inside your module, and then in your local tool script just call SmoothShiftLock:ToggleShiftLock(true, aimDownsightsOffset, v_crosshair). This is cleaner, simpler, and will work both in Studio and in the published game

#

@lime quartz

lime quartz
#

oh I see

#

let me try that

harsh rampart
#

i think i can send u the script

#

updated

lime quartz
#

yeah sure ofc

harsh rampart
#

local ShiftLockModule = require(game.ReplicatedStorage.SmoothShiftLock)

local tool = script.Parent
local aimDownsightsOffset = Vector3.new(0, 0, 0)
local v_crosshair = nil

tool.Equipped:Connect(function()
if not tool then return end
ShiftLockModule:ToggleShiftLock(true, aimDownsightsOffset, v_crosshair)
end)

#

lemme do Module

#

local SmoothShiftLock = {}

function SmoothShiftLock:ToggleShiftLock(toggle, offset, mouseIcon)
if (self.Humanoid and self.Humanoid.Health ~= 0) then
print("ShiftLock toggled:", toggle)
end
end

function SmoothShiftLock:CharacterAdded()
return self
end

return SmoothShiftLock

#

@lime quartz lemme know if it works or if no try what Outpu says

lime quartz
#

alr one sec

harsh rampart
lime quartz
#

i got some more errors, ill ping you when I fix it, might take an hour or two

harsh rampart