local prox = script.Parent
local canbuy = true
game.Players.PlayerAdded:Connect(function(player)
script.Parent.Triggered:Connect(function()
if canbuy == true then
player.leaderstats.fuel.Value = player.leaderstats.fuel.Value + -50
canbuy = false
else
player.leaderstats.fuel.Value = player.leaderstats.fuel.Value + 0
end
end)
end)
what’s supposed to happen:
when a player trigger the ProximityPrompt the script will find the players leaderstats then find the money called “fuel” and if player has 50 fuel then they can walk through the door and lose -50 fuel.
If you can help with making it so when player buys wall and they leave game then when they join the game the wall is still bought and they don’t have to buy it again.
this game is supposed to be like a simulator with other players in a server and the wall is local to people who bought it or not.
It will only run the code after a new player is added I believe, and it would be almost impossible to get it to work because instantaneously it will be done checking the script once. You should put it in a while wait loop or a infinite loop(i might be wrong).
If that does not work then remove the PlayerAdded
local canbuy
local prox = script.Parent
script.Parent.Triggered:Connect(function()
if [something] == 50=> then
canbuy = true
end
if canbuy == true then
player.leaderstats.fuel.Value = player.leaderstats.fuel.Value + -50 -- the + and the -50 don't need to be removed because a plus and a negative make a negative.
canbuy = false
else
player.leaderstats.fuel.Value = player.leaderstats.fuel.Value + 0
end
end)
end)
This code requires a understanding of math, for those saying to remove the + -50. He does not need to because don’t you remember in school a plus and a minus equals a negative. If the value of the fuel is greater than fifty, then 50 will not be accepted. You need to use =>, because that means 50 or greater.
local prox = script.Parent
local canbuy = true
while true do
if prox.TriggerEnded then
local player = prox.Triggered.Parent
local leaderstats = player.leaderstats
local fuel = leaderstats.fuel
fuel.Value = fuel.Value + -50
script.Parent.Parent.Parent.wall.CanCollide = false
script.Parent.Parent.Parent.wall.Transparency = 1
end
if script.Parent.Parent.Parent.wall.CanCollide == false then
break
end
end
local canbuy
local prox = script.Parent
local wall = script.Parent.Parent.Parent.wall
canbuy = false
local players = game:GetService("Players")
local player = players.LocalPlayer
local fuel = player.leaderstats.fuel
if fuel.Value >= 50 then
canbuy = true
end
script.Parent.Triggered:Connect(function()
if canbuy == true then
fuel.Value = fuel.Value + -50
canbuy = false
else
fuel.Value = fuel.Value + 0
end
end)