Global Part Touched Value?

  1. What do you want to achieve? I want to make a part that displays How many times a part has been touched across all servers and update it constantly between servers, and also save the value, example

  2. What is the issue? I just don’t know how to go about this, I am not that good at scripting and I don’t really know how to do global stuff.

  3. What solutions have you tried so far? I have tried to make a Script in ServerScriptService that updates the part frequently, and every time you touch the part it changes the value inside the part.
    The script:

    local sign = workspace[“touch counter”]

    while true do
    sign.main.SurfaceGui.Textvalue.Text = “”…sign.Touches.Value
    wait(50)
    end

Like I said I am not the best at scripting and not good at the global stuff so if you can help me that would be great! Thanks for reading and have a nice day!

You can use the Touched event.
An example would be:

local part = mypart 
part.Touched:Connect(function()
print("Part has been touched!")    
end)

This can be easily done the following way:

--script as a child of the part
local touches = --link the IntValue position
local debounce = false

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if debounce == false then
debounce = true
touches.Value = touches.Value + 1
wait(1)
debounce = false
end
end
end)
--script as a child of the sign

local touches = --link the IntValue position
local text = --link Text Label Position

touches.Changed:Connect(function() 
--using a .Changed function does the same as while loop, but faster and causes less lag

text.Text = "This part has been touched "..touches.Value.." times."

end)
1 Like

Yea but I don’t know how to make it update for all servers if somone in a different server touches it

You can use MessagingService for that.

1 Like

I am using is a script, which is shown on all servers, so all players should see the same thing.

Your script only updates on one server since you’re not sending anything to the other servers but just using Touched on a single server.

1 Like

Ok, but is there a way to save the value when all servers of the game close and the value stays on the part?

DataStoreService may help with storing the amount of times the part has been touched. You should save the value when the server stops, BindToClose will fire a function you gave when it happens.

1 Like

The value, which it is updating, is an IntValue relative to all servers.


I’m sure it doesn’t update on all servers.

1 Like

I am sorry for misunderstanding the purpose. Yeah, IntValues only stay for a specific server, not all servers. :sweat_smile:

1 Like

do what a leaderboard does…

1 Like

I would suggest MessagingService for this type of system. That is meant for just this sort of thing. With messaging service you can PublishAsync() and :SubscribeAsync() when the part is touched using the Touched event

1 Like

You typed sign.main.SurfaceGui.Textvalue.Text = “”…sign.Touches.Value thats not correct because you typed three dots you need to type just 2 here’s the script:

local sign = workspace[“touch counter”]

while true do
sign.main.SurfaceGui.Textvalue.Text = “” …sign.Touches.Value
wait(50)
end

1 Like

Why use concatenation with an empty string if you can just do sign.Touched.Value?

Best way to go about this would probably be to use MessagingService along with DataStoring. I would save the value when the server closes, and communicate when the part is touched with MessagingService.