anthlons
(tatemcraefan45)
September 24, 2019, 10:57am
#1
I cannot really give backstory because I dont know the reasoning behind this?..
My code:
local dss = game:GetService("DataStoreService"):GetDataStore("tBanTestPrivate")
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if msg:sub(1):lower() == "&ban way 1m" then
print('jh1')
dss:SetAsync(plr.UserId, {BanTime = 60, currentServed = 0, timenow = os.time})
print('jh2')
plr:Kick()
print('jh3')
end
end)
end)
jh1 prints, nothing else though.
1 Like
Kacper
(Kacper)
September 24, 2019, 11:01am
#2
Try tostring(plr.UserId) instead of plr.UserId.
anthlons
(tatemcraefan45)
September 24, 2019, 11:01am
#3
plr.UserId is the key, not apart of the dictionary, so I don’t believe it’s the problem.
Kacper
(Kacper)
September 24, 2019, 11:02am
#4
But try it and tell me what happens.
bmcqqqq
(bmcq)
September 24, 2019, 11:03am
#5
{BanTime = 60, currentServed = 0, timenow = os.time}
I suggest you JSONEncode this a string before saving it. This is the issue.
anthlons
(tatemcraefan45)
September 24, 2019, 11:03am
#6
I thought it was done automatically if I’m correct?..
bmcqqqq
(bmcq)
September 24, 2019, 11:04am
#7
I’m not sure if that’s entirely true. I would still try it and see if it works because I do something similar in a game of my own.
Kacper
(Kacper)
September 24, 2019, 11:05am
#8
It rings me a bell that there was a problem when indexing datastore with integers that’s why I suggested my idea. Can you actually try it and tell me if it works?
bmcqqqq
(bmcq)
September 24, 2019, 11:09am
#9
Numeric keys are automatically converted into string. The error has nothing to do with the key and is a problem with what is being stored.
Kacper
(Kacper)
September 24, 2019, 11:09am
#10
GlobalDataStore | Documentation - Roblox Creator Hub it says that the first parameter has to be a string.
bmcqqqq
(bmcq)
September 24, 2019, 11:10am
#11
Screenshot by Lightshot Its automatically converted
1 Like
Kacper
(Kacper)
September 24, 2019, 11:14am
#12
It’s because you’re saving a function os.time instead of the value it returns. ‘os.time()’ should work.
3 Likes
Kacper
(Kacper)
September 24, 2019, 11:16am
#13
I did not know that, thank you
1 Like
regularwolf
(regularwolf)
September 24, 2019, 11:16am
#14
Replace os.time
with os.time()
local dss = game:GetService("DataStoreService"):GetDataStore("tBanTestPrivate")
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if msg:sub(1):lower() == "&ban way 1m" then
print('jh1')
dss:SetAsync(plr.UserId, {BanTime = 60, currentServed = 0, timenow = os.time()})
print('jh2')
plr:Kick()
print('jh3')
end
end)
end)
3 Likes
C_Corpze
(Corpze_TheDeadestOne)
September 24, 2019, 2:28pm
#15
Btw, I recommend wrapping the datastore function in a pcall.
Even though it succeeds most of the time, if it fails due time out or anything
it can cause your script to break.
colbert2677
(ImagineerColbert)
September 24, 2019, 2:32pm
#16
DataStore information is coerced into a string format (potentially JSON) under the hood. JSON encoding data to a DataStore is redundant and unnecessary and it is certainly not required in order to save to DataStores.