Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make this work with Filtering Enabled?

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)

3 comments

0

You are accessing LocalPlayer from a serverscript?

0

what would I use instead?

0

Lol see below VV

1 answer

✓ Accepted answer

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)

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.