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

Remote Event seeming not to work correctly?

Asked by 6 years ago
Edited 6 years ago

I'm trying to make it so when you click a button, it resets your stage and resets your datastore. I'm a beginner to remote events, so this is probably an easy fix.

Here is my code:

--code in the localscript

local data = game:GetService("DataStoreService"):GetDataStore("Stage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local resetDataEvent = ReplicatedStorage:WaitForChild("ResetDataEvent")


script.Parent.MouseButton1Up:connect(function()
    game.ReplicatedStorage.ResetDataEvent:FireServer()
end)




--code in script

local function resetData(plr)
    print("hi")
    plr.leaderstats.Stage.Value = 0
    local key = "user_" .. game.Players.Localplayer.userId
    data:SetAsync(key, game.Players.Localplayer.leaderstats.Stage.Value)
end

game.ReplicatedStorage.ResetDataEvent.OnServerEvent:connect(resetData)

This code is basically ripped off the wiki. Please help!

0
You're using LocalPlayer in a server (regular) script. LocalPlayer won't work in server scripts, only local scripts. User#20279 0 — 6y

1 answer

Log in to vote
0
Answered by
wookey12 174
6 years ago
Edited 6 years ago

in line 17-19 you said:

game.Players.Localplayer.leaderstats.Stage.Value = 0
 local key = "user_" .. game.Players.Localplayer.userId
    data:SetAsync(key, game.Players.Localplayer.leaderstats.Stage.Value)

even though you set a parameter for player. the reason this doesn't work is because it doesn't know what player you are talking about. so because you set a parameter for player (plr) just say:

plr.leaderstats.Stage.Value = 0
 local key = "user_" .. plr.userId
    data:SetAsync(key, plr.leaderstats.Stage.Value)

there might be other errors. im not sure, i didn't test it or do a thorough search, but accept this answer if it did work

Ad

Answer this question