Bug with my zone door script!

You should probably try to format the scripts in a better way for readability.

1 Like
local yourRemote = game.ReplicatedStorage.Events.Buy
yourRemote.OnClientEvent:Connect(function()	
     local Player = game.Players.LocalPlayer
     game.Workspace.Snow:Destroy()
end)

local yourRemote2 = game.ReplicatedStorage.Events.Buy2
yourRemote2.OnClientEvent:Connect(function()
	local Player = game.Players.LocalPlayer
	game.Workspace.DesertDoor:Destroy()
end)


local yourRemote3 = game.ReplicatedStorage.Events.Buy3
yourRemote3.OnClientEvent:Connect(function()
	local Player = game.Players.LocalPlayer
	game.Workspace.Snow1:Destroy()
end)


1 Like

Here’s a better version of your ServerScript:

wait(5)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.Events:WaitForChild("Buy")

local Debounce = false

script.Parent.Touched:Connect(function(hit)
    if Debounce then return end
    print("Touched by " ..hit.Name)
    if hit.Parent:FindFirstChild("Humanoid") then
        print("Humanoid exists.")
        if game.Players:GetPlayerFromCharacter(hit.Parent) then
            print("Player exists.")
            local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if Player:FindFirstChild("leaderstats") then
                print("leaderstats exists.")
                if Player.leaderstats:FindFirstChild("Coins") then
                    print("Value exists")
                    if Player.leaderstats.Coins.Value >= 1250 then
                        Debounce = true
                        print("Player has enough coins!")
                        Player.leaderstats.Coins.Value = Player.leaderstats.Coins.Value - 1250
                        Buy:FireClient(Player)
                        print("RemoteEvent fired.")
                        wait(.2)
                        Debounce = false
                        print("Reset")
                    end
                end
            end
        end
    end
    print("End")
end)
1 Like

If it still doesn’t work, screenshot the output.

1 Like

1 Like

Are you sure that you have enough coins? I don’t think so.

image

It appears that you’re removing coins first, before firing the remote event, and then the remote event also checks to see if they have enough coin. This doesn’t make sense.

player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 1250
Buy:FireClient(player:GetPlayerFromCharacter(hit.Parent))

and then your remote event is doing this…

if Player.leaderstats.Coins.Value >= 1250 then

If they started with 1250 coins, they are going to have 0 coins at this point, so it isn’t going to work.

The problem is that the RemoteEvent doesn’t fire on the ServerScript. The conditions aren’t met.

1 Like

Try this instead.

wait(5)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.Events:WaitForChild("Buy")

local Debounce = false

script.Parent.Touched:Connect(function(hit)
    if Debounce then return end
    print("Touched by " ..hit.Name)
    if hit.Parent:FindFirstChild("Humanoid") then
        print("Humanoid exists.")
        if game.Players:GetPlayerFromCharacter(hit.Parent) then
            print("Player exists.")
            local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if Player:FindFirstChild("leaderstats") then
                print("leaderstats exists.")
                if Player.leaderstats:FindFirstChild("Coins") then
                    print("Value exists " ..Player.leaderstats.Coins.Value)
                    if tonumber(Player.leaderstats.Coins.Value) >= 1250 then
                        Debounce = true
                        print("Player has enough coins!")
                        Player.leaderstats.Coins.Value = Player.leaderstats.Coins.Value - 1250
                        Buy:FireClient(Player)
                        print("RemoteEvent fired.")
                        wait(.2)
                        Debounce = false
                        print("Reset")
                    end
                end
            end
        end
    end
    print("End")
end)

Screenshot the output.

The point is that even if it does fire, the logic is wrong.

1 Like

There’s no logic gate on the LocalScript checking the amount of coins he has.

Are you setting the value of your coins from the client side? In that case, it won’t replicate to the server side.

There was, but it looks like he removed it further down the post and I didn’t see it, since he originally posted this;

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)
2 Likes

Your right i can just do that and on part touch Fire the Client,after we fire client then take awya coins

I mean, if you spawn yourself coins in on the client side, it won’t replicate to the server side and thus a different value printed from the server.

1 Like

i did this on script

local Buy = game:GetService("ReplicatedStorage").Events:WaitForChild("Buy")
local db = false
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
          local player = game.Players:GetPlayerFromCharacter(hit.Parent)
         if db == false then
            db = true
				Buy:FireClient(player)
				player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 1250
			 wait(.2)
            db = false
        end
    end
end)

and this on local script for the event handler

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)

I think @LadyCelastia probably already solved your issue.

It looks like you ran that command in the client window.

You want to click on this and change it to “Current: Server,” then run the command and switch back to the client after.

And then mark @LadyCelastia as having the solution because he said this already, I’m just providing images. :wink:

2 Likes

Thank both of you so much for your help,i got it to work!

2 Likes