Plr showing as nil in gui event

agree
image

I tried replicating the fixes mentioned before on Roblox Studio. Fortunately, they worked.

LocalScript:

local plr = game.Players.LocalPlayer
local RS = game:GetService("ReplicatedStorage")
local BuyEvent = RS.BuyApple

BuyButton.MouseButton1Click:Connect(function()
	BuyEvent:FireServer()
end)

ServerScript:

local ServerStorage = game:GetService("ServerStorage")
local Apple = ServerStorage.Food.Apple
local RS = game:GetService("ReplicatedStorage")
local BuyEvent = RS.BuyApple

BuyEvent.OnServerEvent:Connect(function(plr)
	if plr.leaderstats.Money.Value >= 50 then
		plr.leaderstats.Money.Value -= 50
		local ClonedApple = Apple:Clone()
		ClonedApple.Parent = plr.Backpack
	end
end)

image

Didnā€™t work for meā€¦ There is nothing in serverstorage when I test too.

Can you open and show the Explorer and also run the game so I can see the error occur?

Sure, hereā€™s the video

you have to view them in Server as FilteringEnabled were on, it was made to prevent changes from exploit or unauthorized edits, hence why nothing is there on both ServerScriptService and ServerStorage.
Screenshot_20231108_225439

1 Like

Ok, when I click this it sends me out of the character and sends me into a state kind of like how i am while not testing. I do not know how to buy the apple on the gui if It doesnā€™t let me stay in the character.

Because youā€™re supposed to see this as a server, the game leaves you out to make your camera move in a freecam, Server mode is meant for checking if things were replicated or changed, not for client but you can switch back to client again reverting the camera back to where it was.

buttons cannot work on Server mode

Okā€¦ then how do I test if this works?

What are you testing? If your testing to see if the thing is there in the storage, then enter the Server view like what @pankii_kust said, then check the ServerStorage.

Also maybe when your referencing the buyevent do RS:WaitForChild("BuyApple")

I have done this and added prints. I have found out it is not getting through the if statement in the server script. I tried printing print(plr.leaderstats.Money.Value) and it showed as zero. Was there a problem transferring the plr variable to the server script? Thats my best guess right now. Edit: I noticed that whe I fired the remote event it did not have plr in it I tried this but got the same result

Itā€™s probably because you added money to yourself client-sided, your local scripts mustā€™ve added the money, instead of requesting the server to do so or you probably entered the command to add money client-sided. In order to add it server-sided, simply enter Server view and do the command for adding money.

1 Like

Yes I think this is the problem! Thank I will try this out now

1 Like

Tysm for the help! Have a nice day! :+1: P.S: Everyoneā€™s help led up to the solution so thanks to everyone for putting in time to help me out!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.