i think its because i had no debounce because i was doing it by hit.Parent but db didnt work then itryed changing the doors position after they bought so that they can’t hit anymore!
local db = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Buy = game.ReplicatedStorage.Events.Buy
if db == false then
db = true
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 1250
Buy:FireClient(player:GetPlayerFromCharacter(hit.Parent))
wait(.2)
db = false
end
end
end)
Buy basically just makes the door invisible and cancollide set to false,i woudnt think it would give me a negative number
There are multiple issues with the script.
Firstly, making the part invisible and cannot collide will still fire the .Touched event. I suggest completely deleting it from the LocalScript. Second, you should add a logic gate to check if a player has enough cash to unlock the zone or not. It prevents a player’s cash from going negative. Lastly, just because a model has a humanoid in it, it does not mean that it’s a player. You should check if the Player variable is valid or not.
local db = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Buy = game.ReplicatedStorage.Events.Buy
if db == false then
db = true
if player and player.leaderstats.Coins.Value >= 1250 then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 1250
Buy:FireClient(player:GetPlayerFromCharacter(hit.Parent))
wait(.2)
db = false
end
end
end
end)
i tryed what you said
heres the local script for the events
local yourRemote = game.ReplicatedStorage.Events.Buy
yourRemote.OnClientEvent:Connect(function()
local Player = game.Players.LocalPlayer
if Player.leaderstats.Coins.Value >= 1250 then
game.Workspace.Snow:Destroy()
end
end)
local yourRemote2 = game.ReplicatedStorage.Events.Buy2
yourRemote2.OnClientEvent:Connect(function()
local Player = game.Players.LocalPlayer
if Player.leaderstats.Coins.Value >= 1250 then
game.Workspace.D:Destroy()
end
end)
local yourRemote3 = game.ReplicatedStorage.Events.Buy3
yourRemote3.OnClientEvent:Connect(function()
local Player = game.Players.LocalPlayer
if Player.leaderstats.Coins.Value >= 1250 then
game.Workspace.Snow1:Destroy()
end
end)
local db = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Buy = game.ReplicatedStorage.Events.Buy
if db == false then
db = true
if player.leaderstats.Coins.Value >= 1250 then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 1250
Buy:FireClient(player:GetPlayerFromCharacter(hit.Parent))
wait(.2)
db = false
end
end
end
end)
--//leadersats & Group Benefits\\--
local GroupId = 5032042
local Reward = 500
starting_money = 0
starting_money2 = 0
starting_money3 = 0
function onPlayerEntered(player)
wait(1) --delay for loading time
local leaderstats = Instance.new("IntValue")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"
local Coins = Instance.new("IntValue")
Coins.Parent = leaderstats
Coins.Name = "Coins"
Coins.Value = starting_money
local BC = Instance.new("IntValue")
BC.Parent = leaderstats
BC.Name = "Bread Collected"
BC.Value = starting_money3
local Rebirths = Instance.new("IntValue")
Rebirths.Parent = leaderstats
Rebirths.Name = "Rebirths"
Rebirths.Value = starting_money2
if player:IsInGroup(GroupId) then
Coins.Value = Coins.Value +Reward
end
end
--//MarketPlaceService\\--
local MPS = game:GetService("MarketplaceService")
MPS.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == 686369007 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1000
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 686369345 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 5000
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 686369689 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10000
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 686372686 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50000
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 686373270 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 100000
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 686374019 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1000000
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 6863747509 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 5000000
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 686412335 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 125555555555555555
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
--//Gamepasses\\--
--VIP
local id = 7047605
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
if purchased and ido == id then
--code
end
end)
--Infinite Storage
local id = 7047608
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
if purchased and ido == id then
--code
end
end)
--250+ Storage
local id = 7047611
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
if purchased and ido == id then
--code
end
end)
--500+ Storage
local id = 7047614
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
if purchased and ido == id then
--code
end
end)
--2x Coins
local id = 7047617
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
if purchased and ido == id then
--code
end
end)
local db = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Buy = game.ReplicatedStorage.Events.Buy
if db == false then
db = true
if player.leaderstats.Coins.Value >= 1250 then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 1250
Buy:FireClient(player)
wait(.2)
db = false
end
end
end
end)
``` this is still not working :confused:
local yourRemote = game.ReplicatedStorage.Events.Buy
yourRemote.OnClientEvent:Connect(function()
local Player = game.Players.LocalPlayer
if Player.leaderstats.Coins.Value >= 1250 then
game.Workspace.Snow:Destroy()
end
end)
local yourRemote2 = game.ReplicatedStorage.Events.Buy2
yourRemote2.OnClientEvent:Connect(function()
local Player = game.Players.LocalPlayer
if Player.leaderstats.Coins.Value >= 1250 then
game.Workspace.DesertDoor:Destroy()
end
end)
local yourRemote3 = game.ReplicatedStorage.Events.Buy3
yourRemote3.OnClientEvent:Connect(function()
local Player = game.Players.LocalPlayer
if Player.leaderstats.Coins.Value >= 5000 then
game.Workspace.Snow1:Destroy()
end
end)
local db = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Buy = game.ReplicatedStorage.Events.Buy
if db == false then
db = true
if player.leaderstats.Coins.Value >= 1250 then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 1250
Buy:FireClient(player)
wait(.2)
db = false
end
end
end
end)
local db = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Buy = game.ReplicatedStorage.Events.Buy
if db == false then
db = true
if player.leaderstats.Coins.Value >= 1250 then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 1250
Buy:FireClient(player)
print("Hi")
wait(.2)
db = false
end
end
end
end)
local db = false
script.Parent.Touched:Connect(function(hit)
print("HI")
if hit.Parent:FindFirstChild("Humanoid") then
print("HI")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Buy = game.ReplicatedStorage.Events.Buy
if db == false then
db = true
print("HI")
if player.leaderstats.Coins.Value >= 1250 then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 1250
Buy:FireClient(player)
print("Hi")
wait(.2)
db = false
end
end
end
end)
print("HI")