Still have questions? Join our Discord server and get real time help.
0

# How can I get create an IntValue from a ModuleScript?

J_98482 18
9 months ago

For the block of code below, the ultimate goal is to set up a global IntValue (aka a value that's uniform across all servers) that's incremented whenever a user clicks a part. Currently, I have this code in a ModuleScript in ServerStorage. For one reason or another though, it won't create the IntValue when the part is clicked. I don't believe there are any lua errors in it, as I ran it inside a regular Script, and didn't encounter any errors/issues. If someone could maybe point out what I'm not doing and/or doing incorrectly, I would greatly appreciate it.

This piece of code was made with the help of another SH user in another post, goodvines67. I can also give out more information about the script, if needed.

local clickDetector = game.Workspace.gameparts.clickpart.ClickDetector
local dsService = game:GetService("DataStoreService")
local winDS = dsService:GetDataStore("TimesClicked")
local playerService = game:GetService("Players")

local timesClickedTable = {}

clickDetector.MouseClick:Connect(function(player)
if timesClickedTable[player.UserId] then
timesClickedTable[player.UserId].Value = timesClickedTable[player.UserId].Value + 1
else
local intValueSetup = Instance.new("IntValue")
intValueSetup.Name = "wins"
intValueSetup.Value = 1
timesClickedTable[player.UserId] = intValueSetup
end

end)

playerService.PlayerRemoving:Connect(function(player)
local pUserId = player.UserId
if timesClickedTable[pUserId] then
winDS:IncrementAsync(pUserId, timesClickedTable[pUserId].Value)
end
end)

while true do
wait(50)
if timesClickedTable[player.UserId] then
winDS:IncrementAsync(player.UserId, timesClickedTable[player.UserId].Value)
end
end
end)


0
Did you set the parent for the IntValue instance? Cousin_Potato 129 — 9mo
0
I tried that, but might have done it incorrectly. I set the parent right after line 12, but it didn't seem to do anything, so I left it out of this version J_98482 18 — 9mo