Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to fix part not removed even though it's clicked?

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)

1 answer

✓ Accepted answer

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)

2 comments

0

AIN'T NO WAY MY MIND DID NOT PROCESS THE MOST BASIC THING IN SCRIPT LINE WHICH IS "SCRIPT.PARENT" , anyway yeah it worked now after replacing the line with script.Parent thank you

0

Oh okay, I just re-edited the post because I thought the mistake is in different place now :D. I am glad it worked. If you want I made here server side script which could be used if you wanted to change the mechanics on server side, you are welcome :D.

This discussion is preserved as it was. New answers, comments, and votes are closed.