fro some reasons this script makes 2 or more boxes when I step on the button can someone please help me?
system = script.Parent
model = system.Box --
backup = model:Clone()
regen = system.Regen
local gamepassId = 148550940
local market = game:GetService("MarketplaceService")
script.Parent.Button.Touched:Connect(function(hit)
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if plr then
if market:UserOwnsGamePassAsync(plr.UserId, gamepassId) then
if regen.Value == 1 then
wait(1)
model = backup:Clone()
model.Parent = system
model:MakeJoints()
end
else
market:PromptGamePassPurchase(plr, gamepassId)
end
end
wait(1)
end)
:Touched() is called every frame I believe when something touches the part. Implement a Debounce
print("Hello world, from client!")
system = script.Parent
model = system.Box --
backup = model:Clone()
regen = system.Regen
local gamepassId = 148550940
local market = game:GetService("MarketplaceService")
local Debouce = true
local Interval = 3
script.Parent.Button.Touched:Connect(function(hit)
if (Debouce) then
Debouce = false
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if plr then
if market:UserOwnsGamePassAsync(plr.UserId, gamepassId) then
if regen.Value == 1 then
wait(1)
model = backup:Clone()
model.Parent = system
model:MakeJoints()
end
else
market:PromptGamePassPurchase(plr, gamepassId)
end
end
wait(Interval)
Debouce = true
end
end)
Isn’t that using the same variable (model) and changing it back and forth? Seems like it may be part of your issue (or it’s just confusing me to read).
From my perspective, the script is fine, but the problem is that the Touched event is triggered many times and also, beforehand, you should check if the person who touched the piece is a player:
system = script.Parent
model = system.Box --
backup = model:Clone()
regen = system.Regen
local gamepassId = 148550940
local market = game:GetService("MarketplaceService")
local debounce = true --important !!!!!!!!!!!!!!!!!!!!!!!!!!
script.Parent.Button.Touched:Connect(function(hit)
if debounce then
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if plr then
if market:UserOwnsGamePassAsync(plr.UserId, gamepassId) then
if regen.Value == 1 then
debounce = false--IMPORTANT!!!!!!!!!!!!!!!!!!1
wait(1)
model = backup:Clone()
model.Parent = system
model:MakeJoints()
end
else
market:PromptGamePassPurchase(plr, gamepassId)
end
end
wait(1)
debounce = true--me viole a tu madre
end
end
end)
thanks for telling me but because roblox sends to use task.wait, should I modify my scripts? or what is the difference? is that I use a lot of wait and I don’t want you to tell me to avoid errors in my scripts
Deprecated doesn’t mean it won’t work. They find better and more efficient ways of doing things so they use them. Most deprecated items never get removed, otherwise older games wouldn’t keep working.
Some deprecated items like TorsoMeshes got removed entirely though. Not game breaking, but visually turned them into regular blocks in older builds that used them.