PLEASE HELP ME QUICK I OPEN MY GAME IN 3 HOURS CODE HUNTERS II AND I STILL HAVE SO MUCH WORK TO DO!
HOW DO I MAKE THIS SCRIPT BELOW WORK?!
IT IS LIKE EVERYTHING I DID WEEKS AGO IS BREAKING ON OPENING DAY, PLEASE HELP! D;
script.Parent.Transparency = 0 script.Parent.CanCollide = true script.Parent.Touched:Connect(function(onTouched) script.Parent.Transparency = 1 script.Parent.CanCollide = false game.Players.LocalPlayer.PlayerGui.Essentials.Prize.Visible = true game.Players.LocalPlayer.PlayerGui.Essentials.Prize.Text = 'You have collected 3 Tokens!' game.Players.LocalPlayer.leaderstats.Tokens.Value = game.Players.LocalPlayer.leaderstats.Tokens.Value + 3 wait(0.1) game.Players.LocalPlayer.leaderstats.Tokens.Value = game.Players.LocalPlayer.leaderstats.Tokens.Value + 0 script.Parent.Transparency = 0 script.Parent.CanCollide = true end)
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 --I am making a debounce so the Remote Event is not fired too many times as when you touch a part you touch it more than once. if go == true then go = false script.Parent.Transparency = 1 script.Parent.CanCollide = false game.Players.LocalPlayer.PlayerGui:WaitForChild("Essentials"):WaitForChild("Prize").Visible = true --Added :WaitForChild() so no errors because of it not being there 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 --I'd assume you want that set to false to make it invisible after? wait(2) go = true end end)
Server Script(AKA "Listener Script"):
local remote = game.ReplicatedStorage:WaitForChild("RemoveEvent") remote.OnServerEvent:Connect(function(plr)--First parameter will always be the player who fired the event plr:WaitForChild("leaderstats"):WaitForChild("Tokens").Value = plr:WaitForChild("leaderstats"):WaitForChild("Tokens").Value + 3 --Again I added :WaitForChild() for same reason 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
.