Hello there, I wanted to make a LocalScript where if a player clicks a part, the part is destroyed and another event sequentially occurs (Which is updating the text of the TextLabel named value), however even though it looks correct to me what I expected to happen did not happened, here is the script
NOTE: The reason why there is a WaitForChild in the script is that the book is inside a ReplicatedStorage where it will only be placed in Workspace when a certain event happens
local user = game:GetService("Players").LocalPlayer local book = game.Workspace:WaitForChild("Book") local bookclick = book.ClickDetector local value = user.PlayerGui.BackGui.Value bookclick.MouseClick:Connect(function() book.LocalScript.Parent:Destroy() value.Text += 1 end)
You cannot use math operations on string and number.
local user = game:GetService("Players").LocalPlayer local book = game.Workspace:WaitForChild("Book") local bookclick = book.ClickDetector local value = user.PlayerGui.BackGui.Value bookclick.MouseClick:Connect(function() value.Text = tonumber(value.Text) + 1 script.Parent:Destroy() end)
However, this is in localscript. It will destroy the part only client sided. To remove the part from all clients you will need to make event, or even better make a server script for that. Something like:
local book = workspace:FindFirstChild("Book") or workspace:WaitForChild("Book") local clickDetector = book.ClickDetector clickDetector.MouseClick:Connect(function(player) book:Destroy() local UI = player.PlayerGui:WaitForChild("BackGui"):WaitForChild("Value") UI.Text = tonumber(UI.Text) + 1 end)