So I’m trying to rewrite an old script I made for this tool that dropped a piano and made it explode, but I’m having trouble with a connection.
The variable pianoMarkConnection
dictates when the function markMultiplierVal
will run. When the tool is equipped, the pianoMarkConnection
is set to a RunService.Heartbeat connection that activates the markMultiplierVal
function.
What’s the issue? The issue is the print inside of the markMultiplierVal
function is NEVER fired. Checking the pianoMarkConnection
’s connected boolean also doesn’t print.
This also causes the tool.Activated
function to error, as it says
Workspace.StarJ3M.Piano.Activate:57: attempt to index nil with 'Disconnect' - Client - Activate:57
I already checked if the tool.Unequipped
function is automatically disconnecting the function. But, no it isn’t which is proven by the fact that the print doesn’t run in the output.
What should I do?
local MOUSE_ICON = "rbxasset://textures/GunCursor.png" -- Changes the mouse to the GunCursor Icon.
local RELOADING_ICON = "rbxasset://textures/GunWaitCursor.png" -- Changes the mouse icon to the Gun Wait Curso Icon.
local player = game.Players.LocalPlayer
local tool = script.Parent
local userInputService = game:GetService("UserInputService")
local activateBombRemote = script.Parent:WaitForChild("ActivateBomb")
local pianoMarkMultiplier = 0
local replicatedStorage = game:GetService("ReplicatedStorage")
local pianoModel = replicatedStorage:WaitForChild("Assets"):WaitForChild("Bombs"):WaitForChild("Piano")
local pianoMarkConnection
local pianoMark : Part
local markMesh : SpecialMesh
function markMultiplierVal() -- A connection that when enabled moves the position of the piano mark.
print(pianoMarkConnection.Connected)
if userInputService:IsKeyDown(Enum.KeyCode.Y) and pianoMarkMultiplier ~= 500 then
pianoMarkMultiplier += 1
elseif userInputService:IsKeyDown(Enum.KeyCode.H) and pianoMarkMultiplier ~= 0 then
pianoMarkMultiplier -= 1
end
end
tool.Equipped:Connect(function()
userInputService.MouseIcon = MOUSE_ICON
pianoMark, markMesh = activateBombRemote:FireServer("createPianoMark", nil)
repeat task.wait() until pianoMark ~= nil
pianoMark.Transparency = .5
activateBombRemote:FireServer("pianoMarkPosition", pianoMarkMultiplier)
pianoMarkConnection = game:GetService("RunService").Heartbeat:Connect(markMultiplierVal())
print(pianoMarkConnection.Connected)
end)
tool.Unequipped:Connect(function()
print("Tool Has Been Unequipped.")
pianoMarkConnection:Disconnect()
pianoMark:Destroy()
markMesh:Destroy()
print("Disconnected.")
userInputService.MouseIcon = MOUSE_ICON
end)
tool.Activated:Connect(function()
local cooldownTime = activateBombRemote:FireServer("explodePiano", nil)
pianoMarkConnection:Disconnect()
repeat task.wait() until cooldownTime == false
userInputService.MouseIcon = RELOADING_ICON
userInputService.MouseIcon = MOUSE_ICON
end)