What is wrong with my gui script?

  1. What do you want to achieve?
    When i click a model, I’m trying to make it add 1 to a gui I created. The model is kept in replicated storage, and duplicated across the playing field.

  2. What is the issue?
    When i click the model, it doesn’t add to the gui. I am aware that the gui gets duplicated to playerGui, but that’s not the issue, as i put this in a LocalScript in StarterGui.

  3. What solutions have you tried so far?
    How this is set up:
    script.parent = the ScreenGui
    ScreenGui.Wood.Value = a NumValue to count the times clicked.

local ScreenGui = script.Parent
local TextLabel= ScreenGui.Wood
local Clicker = game.ReplicatedStorage.Tiles.CutDown_Tile.ClickDetector
function Click()
	ScreenGui.Wood.Value.Value = ScreenGui.Wood.Value.Value + 1
	TextLabel.Text = ScreenGui.Wood.Value.Value
	print (ScreenGui.Wood.Value.Value)
end
Clicker.MouseClick:Connect(Click)

What i think may be the issue, is that the script is referring to the tile in ReplicatedStorage, not the one in workspace. But I have no clue on where to refer to the one that the player is clicking. Please help!

I’m not sure I get the issue you’re having, but two problems are rather obvious here:

  1. A client changing a Value in a LocalScript won’t change the value on the sever or on any other client. See more: Custom Events and Callbacks | Documentation - Roblox Creator Hub
  2. ClickDetectors don’t work in ReplicatedStorage, only in workspace. When you duplicate the model all events connected to the ClickDetector are removed for the cloned instance. The only way to first connect to the ClickDetector events, then to put it into workspace, is to reparent it. You have to first clone the CutDown_Tile, then bind to the ClickDetector events.

So how do i know which tile is being clicked?

There’s no way to define “which” tile you’re clicking unless you make them distinguishable - different names, colors, positions, a string value inside with a name… whichever quality you choose to distinguish them, you will use to figure out which tile gets clicked.

I mean, I know which tile i’m clicking, but how do i make the script know which one?

I’m not sure why you would want the script to know that?

Basically, what i’m doing is the tile you’re clicking on is a fallen tree. When you click on it, it’ll add to the “Wood” gui and subtracting from it’s own variable.

I suggest you make a Script inside the part that gets clicked that listens for player clicks and sends RemoveEvent calls to the client telling them to update their GUI whenever they get more wood. Since you then have a Script inside each ClickDetector part, you know which part is being clicked via script.Parent.

Okay, thanks! Never mind what i said about telling me how to do it, I’ll learn by myself.