while wait(0.001) do local required_points = 100000 local db = true script.Parent.Touched:connect(function(hit) local player = hit.Parent if hit.Parent:FindFirstChild("Humanoid")then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player.leaderstats.Coins.Value >= required_points then if db then db = false script.Parent.Transparency = 0.5 script.Parent.CanCollide = false end else print("you haven't enough money") end end end) end
idk why it is not working it is working in a normal script but the problem is that a other players can go threw when a player with 100K touches the door
First off remove the while loop. It is not needed. And please don't call wait
with such a small number, at least call it with 1/10
. And do not use that call as condition of while loop as you don't know how it works. Don't follow conventions just for being popular, follow them because you know how they work.
It lets other people through because you never set CanCollide
back to true
. If you want you can teleport a player through the brick.
local REQUIRED_POINTS = 100000 local db = true local door = script.Parent local Players = game:GetService("Players") door.Touched:Connect(function(part) -- :connect is deprecated in favour of :Connect local player = Players:GetPlayerFromCharacter(part.Parent) if player and player.leaderstats.Coins.Value >= REQUIRED_POINTS then if db then db = false door.Transparency = 0.5 player.Character:SetPrimaryPartCFrame(door.CFrame*CFrame.new(0, 0, -10)) wait(2) door.Transparency = 0 else print("you haven't enough money") end end end)
This should teleport them 10 studs forward. Or you could quickly set it back to false but what if a player is behind them.