You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to make it so when the image button is clicked that the leaderstat and gui update their values after being pressed. -
What is the issue? Include screenshots / videos if possible!
The issue I am experiencing is that when I try it in the Roblox player, it no longer works but when testing it in Roblox studio it works just as intended. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried changing the event from activated to inputbegan and mousebutton1click. Also tried to make sure the player was fully loaded in the game by adding some waits and using character added but still will not work in the Roblox player.
Here is a copy of my local script that I have in startergui
local players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local soundsFolder = ReplicatedStorage:WaitForChild("SoundsFolder")
local soundList = soundsFolder:GetChildren() -- Get all sounds in the folder
local player = players.LocalPlayer or players:WaitForChild("LocalPlayer")
local screenGui = player.PlayerGui:WaitForChild("ScreenGui")
local imageButton = screenGui:WaitForChild("ImageButton")
local leaderstats = player:WaitForChild("leaderstats")
local clicksValue = leaderstats:FindFirstChild("Clicks")
local debounce = false
local debounceTime = 0.1 -- Adjust this time as necessary
local updateClicksEvent = ReplicatedStorage:FindFirstChild("UpdateClicks")
local confetti = require(game.ReplicatedStorage:WaitForChild("ConfettiScript"))
local confettiTable = {
100,
200,
300,
410,
500,
600,
678,
777,
1000
}
-- Update the TextLabel with the current Clicks value initially
screenGui:WaitForChild("TextLabel").Text = tostring(clicksValue.Value)
-- Function to play a random sound
local function playRandomSound()
if #soundList > 0 then -- Ensure there are sounds in the folder
local randomSound = soundList[math.random(1, #soundList)] -- Select a random sound
randomSound:Play() -- Play the selected sound
else
warn("No sounds found in the folder!")
end
end
-- Function to check if confetti should play
local function checkConfetti(newValue)
for _, threshold in ipairs(confettiTable) do
if newValue == threshold then
playRandomSound()
confetti.Play()
break
end
end
end
-- Update the TextLabel whenever the Clicks value changes in leaderstats
clicksValue.Changed:Connect(function(newValue)
screenGui.TextLabel.Text = tostring(newValue)
checkConfetti(newValue)
end)
-- Increment Clicks when the player clicks the image
imageButton.Activated:Connect(function()
if not debounce then
debounce = true
updateClicksEvent:FireServer(clicksValue.Value + 1)
task.wait(debounceTime)
debounce = false
end
end)
-- Initial check to see if confetti should play (if the player already has enough clicks)
checkConfetti(clicksValue.Value)