I am making a music module for my game, but for some reason whenever I try firing my tween bindable event, it gives this error:
The current thread cannot fire 'TweenFromClient' since 'TweenFromClient' has the Sandboxed property set to false but the calling thread is sandboxed
Video of the issue:
Music module:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
local Players = game:GetService("Players")
local MusicGroup = SoundService:WaitForChild("Music")
local player = Players.LocalPlayer
local pgui = player:WaitForChild("PlayerGui")
local Modules = ReplicatedStorage.Modules
local DebugModules = Modules.Debug
local Dependencies = Modules.Dependencies
local Events = ReplicatedStorage.Events
local Tween = Events:WaitForChild("TweenFromClient")
local musicZones = workspace:WaitForChild("MusicZones")
local DebugPrint = require(DebugModules:WaitForChild("DebugPrint"))
local Visualizer = require(script.VisualizerModule)
local QuickZone = require(Dependencies:WaitForChild("QuickZone"))
local Zone, Group, Observer = QuickZone.Zone, QuickZone.Group, QuickZone.Observer
local songGui = script.SongGui
local myPlayer = Group.localPlayer()
local currentZones = {}
local currentVisualizer
local lastPlayingSong
local tweenWait = 0
local started = false
local zones = {}
for _, model in ipairs(musicZones:GetChildren()) do
if not model or not model:IsA("Model") then return end
local parts = Zone.fromChildren(model)
local observer = Observer.new():subscribe(myPlayer):attach(parts)
table.insert(zones, {Zones = parts, Observer = observer, Name = model.Name})
end
local music = {}
music.Debug = true
music.Name = "MUSIC MODULE"
local function cleanupVisualizer()
if currentVisualizer then
currentVisualizer:Destroy()
currentVisualizer = nil
end
end
local function createVisualizer(song)
if currentVisualizer then return end
if not song then return end
local newGui = songGui:Clone()
currentVisualizer = newGui
local mainFrame = newGui.Frame
local visualizerHolder = mainFrame.Visualizer
local songText = mainFrame.SongName
mainFrame.Position = UDim2.new(1.3,0,0.9,0)
songText.Text = songText:GetAttribute("SongName") or song.Name
newGui.Parent = pgui
Events:WaitForChild("TweenFromClient"):Fire({
[1] = { Object = mainFrame, TI = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), Goal = {Position = UDim2.new(1,0,0.9,0)}, DelayTime = nil }
})
local newVisualizer = Visualizer.new(visualizerHolder, 50)
newVisualizer:LinkToSound(song)
end
local function toggleSong(song, state)
if not song then return end
if state and lastPlayingSong == song then return end
lastPlayingSong = (state and song) or nil
if state then
song:Play()
createVisualizer(song)
else
song:Stop()
end
end
function music:Start()
if started then return end
started = true
for _, data in ipairs(zones) do
if not data.Observer or not data.Zones then return end
data.Observer:onLocalPlayerEnter(function(zone)
local character = player.Character
local hrp = character and character:FindFirstChild('HumanoidRootPart')
if not hrp then return end
currentZones[data.Name] = true
task.spawn(function()
toggleSong(MusicGroup:FindFirstChild(data.Name), true)
end)
DebugPrint(music, character, " entered.")
end)
data.Observer:onLocalPlayerExit(function(zone)
local character = player.Character
local hrp = character and character:FindFirstChild('HumanoidRootPart')
if not hrp then return end
currentZones[data.Name] = nil
print(currentZones)
task.spawn(function()
toggleSong(MusicGroup:FindFirstChild(data.Name), false)
end)
DebugPrint(music, character, " exited.")
end)
end
end
return music
Script that handles the tweening (StarterPlayerScripts)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Events = ReplicatedStorage:WaitForChild("Events")
local RemoteEvent = Events:WaitForChild("TweenClient")
local BindableEvent = Events:WaitForChild("TweenFromClient")
local function tween(Tweens)
for _, data in ipairs(Tweens) do
if not data.Object
or not data.TI
or not data.Goal
then
continue
end
if data.DelayTime then
task.wait(data.DelayTime)
end
if not data.Object or not data.Goal then return end
TweenService:Create(data.Object, data.TI, data.Goal):Play()
end
end
RemoteEvent.OnClientEvent:Connect(function(Tweens)
tween(Tweens)
end)
BindableEvent.Event:Connect(function(Tweens)
tween(Tweens)
end)
Other scripts that use this tween event work perfectly fine. I’ve never had this issue before.
I’ve tried wrapping it in a task.spawn() function but it didn’t work. And I have no idea whats causing this or how to fix it.
