✓ Accepted answer
Problem:
If you want to use Filtering Enabled and manipulate a player's stats it is best you do it with a Remote Event. Simply doing it, which I assume you are doing it in, a Local Script will only change the player's values on the client side not the server side.
Solution:
Like I mentioned above I would use a Local Script to register the Touched event of the part and can manipulate the Player's Gui, but use a Remote Event to actually manipulate the Player's Stats. Now when I reference in a variable to the Remote Event you can change the reference to it in the hierarchy of the game as you please. In general it would look something like this with a Local Script and a "Listener" script.
Code:
Local Script:
script.Parent.Transparency = 0
script.Parent.CanCollide = true
local remote = game.ReplicatedStorage:WaitForChild("RemoveEvent")
script.Parent.Touched:Connect(function(onTouched)
local go = true
if go == true then
go = false
script.Parent.Transparency = 1
script.Parent.CanCollide = false
game.Players.LocalPlayer.PlayerGui:WaitForChild("Essentials"):WaitForChild("Prize").Visible = true
game.Players.LocalPlayer.PlayerGui.Essentials.Prize.Text = 'You have collected 3 Tokens!'
remote:FireServer()
script.Parent.Transparency = 0
script.Parent.CanCollide = true
game.Players.LocalPlayer.PlayerGui:WaitForChild("Essentials"):WaitForChild("Prize").Visible = false
wait(2)
go = true
end
end)
Server Script(AKA "Listener Script"):
local remote = game.ReplicatedStorage:WaitForChild("RemoveEvent")
remote.OnServerEvent:Connect(function(plr)
plr:WaitForChild("leaderstats"):WaitForChild("Tokens").Value = plr:WaitForChild("leaderstats"):WaitForChild("Tokens").Value + 3
end)
If you have any problems you can comment on my answer and I would be glad to help. If this helped you then don't forget to accept my answer. Also note that you can put the "Listener Script" where you want, but not ServerScriptService or ServerStorage as these areas are for the server side only and not the client really. But you get my point. It should also be considered to name your RemoteEvent so that the "Listener Script" listens to the right Remove Event.
1 comment
Please show errors.