I feel like there’s too much if statements and it looks pretty messy. Also is it normal for scripts to run at 5 rate per second? Can you please help me optimize my code and shorten it if possible?
-- This is a server script
local debounce = false
script.Parent.Head.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if debounce == false then
debounce = true
if player ~= nil then
local PlayerStats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
if PlayerStats ~= nil then
local ownstycoon = PlayerStats:FindFirstChild("OwnsTycoon")
print(ownstycoon)
if ownstycoon ~= nil then
if ownstycoon.Value == nil then
if script.Parent.Parent.Parent.Owner.Value == nil then
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent.Humanoid.Health > 0 then
script.Parent.Parent.Parent.Owner.Value = player
ownstycoon.Value = script.Parent.Parent.Parent
script.Parent.Name = player.Name.."'s Tycoon"
end
end
end
end
end
end
end
wait(5)
debounce = false
end
end)