script.Parent.Frame.Yes.MouseButton1Click:Connect(function()
script.Parent:TweenPosition(UDim2.new(0.336,0,-1,0), "Out", "Quad", 1)
local plr = game.Players.LocalPlayer
if car == "Car1" then
if plr.leaderstats.Money.Value < 5000 then
game.ReplicatedStorage.NeedMoney:FireServer(plr)
else
game.ReplicatedStorage.Carhandler:FireServer(car)
end
end
if car == "Car2" then
if plr.leaderstats.Money.Value < 10000 then
game.ReplicatedStorage.NeedMoney:FireServer(plr)
else
game.ReplicatedStorage.Carhandler:FireServer(car)
end
end
if car == "Car3" then
if plr.leaderstats.Money.Value < 20000 then
game.ReplicatedStorage.NeedMoney:FireServer(plr)
else
game.ReplicatedStorage.Carhandler:FireServer(car)
end
end
if car == "Car4" then
if plr.leaderstats.Money.Value < 20000 then
game.ReplicatedStorage.NeedMoney:FireServer(plr)
else
game.ReplicatedStorage.Carhandler:FireServer(car)
end
end
end)
end)
On the top of all scripts that reference something in ReplicatedStorage, you would include local repl = game:GetService("ReplicatedStorage"), then anything inside ReplicatedStorage can be referenced with repl.something, replacing something with whatever you intend to reference of course.
Yes, except using :GetService() every single time when it’s needed is inefficient. It’s better to call it once and assign it to a variable, like I did.
im surprised that he used FireServer on the first script and he OnClientEvent on the second i just dont understand what he wants until he shows the server script
There’s a few things wrong with this. Firstly, you’re sending a :FireServer() with the Player as a parameter. A RemoteEvent will always fire to server with player as the first argument, without you having to send it yourself.
RemoteEvent:FireServer()
-- what the server receives
RemoteEvent.OnServerEvent:Connect(function(player)
...
end)
Also, I see you are firing an event to the server with the remote, then I’m confused on are you trying to read that fire from a LocalScript? Or is that feedback? If it’s feedback, use a RemoteFunction instead. Otherwise, the way remotes work is that you send a :FireServer() command to the server, and in a regular Script you’ll have:
All in all, if you’re going to be using RemoteEvents at all, I suggest handling this all in the server to begin with. Don’t calculate in the client and instead Fire what you want to buy, and let the server calculate if that’s possible:
-- client
RemoteEvent:FireServer("Car1") -- request to buy Car 1 to server...
-- server
RemoteEvent.OnServerEvent:Connect(function (player, request)
if request == "Car1" then
if enoughMoney(player) then -- where enoughMoney is the way to determine if there is enough money in the player
giveCarToPlayer(player) -- where you handle giving the purchase
end
end
end)
This is more of a template-style pseudocode, but it shows how you’d manage server-sided calculations to ensure that the client isn’t lying about how much money they have.