Problem With Tycoon Beam

Hello, I’ve been working on a tycoon for about 2 week. I’m using Zednov’s tycoon kit. I want it to create tycoon arrows/beams, but the problem is when you claim a tycoon beams doesn’t
disappear :

This is the script that im using it ;

local Players = game:GetService("Players")
local Character = Players.LocalPlayer.CharacterAdded:wait()

print ("Creating Beams...")

--references the "Entrance" part
local tycoonDoors = {
	game.Workspace["Zednov's Tycoon Kit"].Tycoons["Test Tycoon 1"].Entrance,
	game.Workspace["Zednov's Tycoon Kit"].Tycoons["Test Tycoon 2"].Entrance,
}

local function createBeams()
	for i,v in pairs(tycoonDoors) do
		if v:FindFirstChild("Touch to claim!") then --this checks if a tycoon is claimable, and only creates the beam if it is
			local beam = Instance.new("Beam")
			beam.Parent = v["Touch to claim!"].Head
			-- Settings --
			beam.Texture = "rbxassetid://17070105"
			beam.TextureLength = 7
			beam.TextureMode = "Static"
			beam.TextureSpeed = 1
			beam.FaceCamera = true
			--          --
			local attachmentPlayer = Instance.new("Attachment")
			attachmentPlayer.Name = "TycoonArrow"
			attachmentPlayer.Parent = Character:WaitForChild("HumanoidRootPart")

			beam.Attachment1 = v["Touch to claim!"].Head.Attachment
			beam.Attachment0 = attachmentPlayer
		end
	end
end

createBeams()

local function disableBeams()
	for i,v in pairs(tycoonDoors) do
		if v:FindFirstChild("Touch to claim!") then --just applying the same checks as before
			if v["Touch to claim!"].Head:FindFirstChildOfClass("Beam") then -- Checks the beam
				v["Touch to claim!"].Head.Beam.Enabled = false
			end
		end
	end
end

local function enableBeams()
	for i,v in pairs(tycoonDoors) do
		if v:FindFirstChild("Touch to claim!") then
			if v["Touch to claim!"].Head:FindFirstChildOfClass("Beam") then
				v["Touch to claim!"].Head.Beam.Enabled = true
			end
		end
	end	
end
print ("Created Beams!")

Thanks in advance to anyone who can help.

You need to check if a tycoon is already claimed by the player. If you have a value somewhere telling you if it’s claimed or not, use that to check in the script.

1 Like

I found this in the gate script. There is a local that checks if you own a tycoon.

script.Parent.Head.Touched:connect(function(hit)
local script1 = script.Parent.Head.Touched	
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player ~= nil then
		local PlayerStats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
		if PlayerStats ~= nil then
			local ownstycoon = PlayerStats:FindFirstChild("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"
								script.Parent.Head.Transparency = 0.6
								script.Parent.Head.CanCollide = false 
								
								
								player.TeamColor = script.Parent.Parent.Parent.TeamColor.Value
							end
						end
					end
				end
			end
		end
	end
end)

Then look for a value called “OwnsTycoon” inside the “playerstats”, then check if a value exists in there. That way you can determine if the player owns a tycoon or not.

The other way around, if you need to check if the tycoon is owned or not, just check “script.Parent.Head.Name”, as it seems to change when people claim it.

1 Like

You could temporary store any beam which gets created inside an array, then when the function runs again loop through all the current beams and destroy them:

local beams = {} --storing beams in an array, must be placed above the createBeams function

--at the start of createBeams function
for _, beam in pairs(beams) do 
	beam:Destroy()
end

--when the beams get parented
beam.Parent = v["Touch to claim!"].Head 
table.insert(beams, beam)
1 Like

Yeah, and then when another tycoon is claimed, an event could be fired. That way, all clients would know to delete that beam.

1 Like

Sadly the beam didn’t get destroyed. I think its because when you claim the tycoon [“Touch to claim!”] name changes, Example : [“Roblox’s Tycoon”]

Not claimed ;
image

Claimed ;