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

How to make this work with Filtering Enabled?

Asked by 5 years ago

So I've tried to do this but it seems it will work inside Studio but not inside the actual game, so it must be something to do with FE, so could someone please help me make it work with FE?

Client Side:

local codes = script.Parent.Parent.Codes -- location of the codes
local ds = game:GetService("DataStoreService")
local store = ds:GetDataStore("CodeSave")


script.Parent.MouseButton1Down:Connect(function()
    if script.Parent.Parent.codeBox.Text == "Alpha" then
        if codes.Alpha.Value == true then
            script.Parent.Parent.codeBox.Text = "Already Redeemed!"
        end
        if codes.Alpha.Value == false then
            codes.Alpha.Value = true
            game.ReplicatedStorage.GiveMoney:FireServer()
            script.Parent.Parent.codeBox.Text = "Redeemed!"
        end
    end
end)

Server Side:

game.ReplicatedStorage.GiveMoney.OnServerEvent:connect(function()
    local codes = game.StarterGui.CodeSystem.RedeemArea.Codes
    game.Players.LocalPlayer.leaderstats.Credits.Value = 
        game.Players.LocalPlayer.leaderstats.Credits.Value + codes.Alpha.Reward.Value
end)
0
You are accessing LocalPlayer from a serverscript? TiredMelon 405 — 5y
0
what would I use instead? K1ng_Phant0m 13 — 5y
0
Lol see below VV TiredMelon 405 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You can't access local player from a server script. It makes no sense since the script is on the server not a specified client.

When you fire a remote event it automatically passes the player that fired the event as the first argument.

game.ReplicatedStorage.GiveMoney.OnServerEvent:connect(function(player)
    local codes = game.StarterGui.CodeSystem.RedeemArea.Codes

    player.leaderstats.Credits.Value = player..leaderstats.Credits.Value + codes.Alpha.Reward.Value
end)
0
Thanks! K1ng_Phant0m 13 — 5y
Ad

Answer this question