Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Im trying to the My Reviews but It dosnt Work Properly [SOLVED]?

Asked by 4 years ago
Edited 4 years ago

This is the script to save the reviews Thumbs Up, but when someone review it Dosnt add any reviews and Sometimes adds like 30 Reviews to the value when Its suppose to add 1

local ReviewName = "ThumbsUp"
local DS = game:GetService("DataStoreService"):GetDataStore("ReviewThumbsUp9785292371")

if not DS:GetAsync(ReviewName.."-Review") then
DS:SetAsync(ReviewName.."-Review",0)
end

local Reviews = DS:GetAsync(ReviewName.."-Review")
game.Workspace.ReviewValues.ThumbsDown.Value = DS:GetAsync(ReviewName.."-Review")

function PrintOut(Value)
print(Value)
end

game.Workspace.ReviewValues.ThumbsUp.Changed:Connect(function()
DS:IncrementAsync(ReviewName.."-Review",game.Workspace.ReviewValues.ThumbsUp.Value)
DS:OnUpdate(ReviewName.."-Review",PrintOut)
wait(1)
game.Workspace.ReviewValues.ThumbsUp.Value = DS:GetAsync(ReviewName.."-Review")
end)

coroutine.resume(coroutine.create(function()
while wait() do
local Reviews = DS:GetAsync(ReviewName.."-Review")
game.Workspace.ReviewValues.ThumbsUp.Value = DS:GetAsync(ReviewName.."-Review")
end
end))
0
How does it not work properly? (also indent your code) Asceylos 562 — 4y
0
When someone reviews the value dosnt go up and sometimes adds like 30 reviews to the value KennaUTB 5 — 4y
1
I dont even know what your trying to do.. You cant just post a question and paste some code. You will need to explain to us. mc3334 649 — 4y

3 answers

Log in to vote
1
Answered by
mc3334 649 Moderation Voter
4 years ago

I may not be able to pinpoint your error, but I know for a fact that this doesent work for multiple reasons. Reason 1, in my eyes you method of getting the data just gets the same data in certain spots and uses it for different stuff. Reason 2, at line 22 just use spawn(function(), reason 3, calling data out of a datastore every .01 seconds or whatever you have wait() set to, is way to often. Your overloading the APIs. This would be a lot easier to manage if you would reformat your code properly by indenting. Then change what I said above. Please edit your question when you have changed the above.

0
PLUS, your code and question were phrased improperly. mc3334 649 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I figured this out, it was Because the Datastore was ImcrementAsync instead of SetAsync

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

the code is kinda of hard to read and understand here is what i think ur trying to do:

when a player clicks some sort of button or whatever to thumbs up something, it will add to the number of thumbs up in the store data of current reviews and similarly to the thumbs down right? and the reviews are not for a specific player, but generally for everyone to rate and see

if so, here is better way to do it.

Note: takes 5 seconds to update

local datstoreName = "name of data store goes between the the quotes"
local key = "reviews unique key goes here"
local datastore = game:GetService("DatastoreService"):GetDatastore(datastoreName)

local awaitingReviews = {}
local db = false

function rateProduct(rating) --change this name
    if not db then
        db = true
        reviews = datastore:GetAsync(key)
        reviews = (reviews or 0)+rating

        datastore:SetAsync(key,reviews)
        wait(5)
        db = false
        table.foreach(awaitingReviews,rateProduct)
    else
        awaitingReviews[#awaitingReviews +1] = rating
    end
end

so how this function works is:

you pass it either a 1 or -1 to to indicate thumbs or down:

-1 down

1 up

if u have some sort of a thing that lets players see both numbers of likes and dislikes then you can simply add an if statement to modify the function

sorry the code is not in the best form. i was in a car accident and came out injured, which is kind of limited me from doing my best; sorry

Answer this question