i am working on a lightsaber game and i want to add mobile buttons.
the weird thing is tho the mobile buttons work when you first join but when you reset they dont work anymore?
this is an example of what i mean + it has no errors in the output:
here is the code used for the buttons:
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait() --if character hasnt loaded yet, wait
local function onclick()
local Lightsaber = Char:FindFirstChild("Lightsaber IV Dual") --im assuming this is the tool
if Lightsaber and Char then
local EnableFolder = Lightsaber:WaitForChild("Enable/Disable") --assuming this is a folder
local EnableEvent = EnableFolder:WaitForChild("EnableSaber")
local sound = Lightsaber.lightsaberonidle
if EnableEvent then
EnableEvent:FireServer()
sound:Play()
script.Parent.Parent.Parent.Visible = false
script.Parent.Parent.Parent.Parent.WhenEnabled.Visible = true
script.Parent.Ignite:Play()
end
end
end
script.Parent.MouseButton1Click:connect(onclick)
Based on the code provided, it seems that the issue might be related to the event listener not being properly reconnected after a reset. When you reset the game, the script is likely being reloaded, but the event listener for the button click is not being reconnected.
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local function onClick()
local Lightsaber = Char:FindFirstChild("Lightsaber IV Dual")
if Lightsaber and Char then
local EnableFolder = Lightsaber:WaitForChild("Enable/Disable")
local EnableEvent = EnableFolder:WaitForChild("EnableSaber")
local sound = Lightsaber.lightsaberonidle
if EnableEvent then
EnableEvent:FireServer()
sound:Play()
script.Parent.Parent.Parent.Visible = false
script.Parent.Parent.Parent.Parent.WhenEnabled.Visible = true
script.Parent.Ignite:Play()
end
end
end
script.Parent.MouseButton1Click:Connect(onClick)
Player.CharacterAdded:Connect(function(character)
Char = character
end)