Clickdetector doesn't work

I’m working on adding a halloween update to my Piggy game, and the event is to collect candys. This is the collect candy script

script.Parent.MouseClick:Connect(function()
game.Players.LocalPlayer.PlayerGui.Halloween2024.CandysCollected.Value += 1
end)

there isn’t any errors, but it doesn’t work.

1 Like

Are all the assets present in the game and correctly parented to the parts, and does the ClickDetector register being clicked? Example: print(“Clicked!”)

script.Parent.MouseClick:Connect(function(player)
player.PlayerGui.Halloween2024.CandysCollected.Value += 1
end)

Just added that print script. Doesn’t register.

im guessing this is a server script under then click detector, game.Players.LocalPlayer will not work, you will have to do fire a remote to the client side to change the ui

The script is a LocalScript. I can’t have it be a ServerScript because I want to destroy the candy object eventually from that script.

looks like this is in a localscript, my guess is that it isnt effecting the server but is effecting the client. look at the candyscollected value on both the client and server to see if its changing.

The candy collected value is in a screengui

Convert it to a normal script and change the RunContext to local

1 Like

I don’t think that’ll work because the script is being put inside the object using a localscript.

local function Typewrite(Label,Text)
if typeof(Label) == “Instance” and typeof(Text) == “string” then
for i = 1,#Text,1 do
Label.Text = string.sub(Text,1,i)
task.wait(0.065)
end
end
end

local function TweenCam(Camera)
if typeof(Camera) == “Instance” then
game:GetService(“TweenService”):Create(workspace.CurrentCamera,TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),{CFrame = Camera.CFrame}):Play()
end
end

game.ReplicatedStorage.GeorgieHalloween2024TalkTo.OnClientEvent:Connect(function(georgie, proximity)
proximity.Enabled = false
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CameraSubject = georgie.Camera
TweenCam(georgie.Camera)
script.Pig:Play()
Typewrite(script.Parent.Dialog, “Hey!! You there, could you help me find my Candy?”)
task.wait(2)
script.Pig:Play()
Typewrite(script.Parent.Dialog, “I was walking around and I realized I was missing my Candy Basket!”)
task.wait(1)
script.Pig:Play()
Typewrite(script.Parent.Dialog, “If you are able to help me, I’ll give you a limited time badge!”)
task.wait(1)
script.Parent.CandyIcon.Visible = true
script.Parent.Candys.Visible = true
TweenCam(game.Players.LocalPlayer.Character.Head)
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Head
proximity.Enabled = true
for i, candy in pairs(workspace.Halloween2024.Candy:GetChildren()) do
candy.Transparency = 0
local CandyScript = script.CandyScript:Clone()
CandyScript.Parent = candy.ClickDetector
CandyScript.Enabled = true
end
end)

localscripts can only run when parented to specific parents, setting a script’s runcontext to local will allow it to run in the workspace (which is my second guess as to why nothing is happening)

It worked! Thanks, I thought it wouldn’t work because I thought RunContext would just basically turn it into a LocalScript.

1 Like