Error in my script

Hello,
I am trying to fix my beam script that i got from another game of mine, it does not work when placed in another game. Is this something to do with values?

When i copy and paste a value into another game, the value changes to nil. I think this error could be something to do with that.

I have no idea what this error means, I’ve spent days looking for it. I’m slowly giving up

I can’t even find Attachment1 in explorer, or find out what it means in the script.
The script has been provided in the comments.

(I am not a scripter, if you couldn’t tell)

Thanks!

-- --//Services
local soundService = game:GetService("SoundService")
local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TweenService")
local MPS = game:GetService("MarketplaceService")
local PS = game:GetService("Players")
--//Locals
local remoteEvents = RS:WaitForChild("remoteEvents")
local plr = PS.LocalPlayer
--//Tween Infos
local tweenInfoBuild = TweenInfo.new(1,Enum.EasingStyle.Back,Enum.EasingDirection.Out)

remoteEvents:WaitForChild("tycoonEvent").OnClientEvent:Connect(function(data)
	local infoType = data.infoType
	if infoType == "playSound" then
		local soundId = data.soundId
		local sound = Instance.new("Sound"); sound.SoundId = tostring("rbxassetid://"..soundId)
		soundService:PlayLocalSound(sound)
		sound.Ended:Wait()
		sound:Destroy()
	elseif infoType == "purchaseTween" then
		local object = data.object
		for i,v in pairs(object:GetDescendants()) do
			if v:IsA("BasePart") then
				coroutine.resume(coroutine.create(function()
					local oldSize = v.Size
					v.Size = Vector3.new(0,0,0)
					local tween1 = TS:Create(v,tweenInfoBuild,{Size = oldSize})
					tween1:Play()
					tween1.Completed:Wait()
					v.Size = oldSize
				end))
			end
		end
	elseif infoType == "productPurchase" then
		local productId = tonumber(data.productId)
		MPS:PromptProductPurchase(plr,productId)
	elseif infoType == "gpassPurchase" then
		local gpassId = tonumber(data.gpassId)
		MPS:PromptGamePassPurchase(plr,gpassId)
	elseif infoType == "ownerDoorIcon" then
		local clickDetector = data.clickDetector
		local types = data.types
		if types == true then
			clickDetector.CursorIcon = "rbxassetid://6867204209"
		else
			clickDetector.CursorIcon = "rbxassetid://6867202834"
		end
	elseif infoType == "passSelector" then
		local chatprop = data.chatProp
		game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",chatprop)
		local Image = data.Image
		local Id = data.passId
		local gui = plr.PlayerGui:WaitForChild("LimitedTimeEvent")
		gui.Background.Id.Value = 0
		wait(.1)
		gui.Background.Id.Value = Id
		gui.Background.Icon.Image = Image
		gui.Background.Position = UDim2.new(1.5,0,0.38,0)
		gui.Background:TweenPosition(UDim2.new(1, 0, 0.2, 0),Enum.EasingDirection.Out,Enum.EasingStyle.Back,1,true)
	elseif infoType == "message" then
		local chatprop = data.chatProp
		game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",chatprop)
	end
end)

local suffixes = {'','K','M','B','T','q','Q','Sx','Sp','Oc','N','de','U','D','Td','Qdn','Qnd','Sxd','Spd','Ocd','NvD','Vgn','UVg','DVg','TVg','qtV','QnV','SeV','SPG','OVG','NVG','TGN','UTG','DTG','tsTG','qtTG','QnTG','ssTG','SpTG','OcTG','NoAG','UnAG','DuAG','TeAG','QdAG','QnAG','SxAG','SpAG','OcAG','NvAG','CT'}
local function format(val)
	for i=1, #suffixes do
		if tonumber(val) < 10^(i*3) then
			return math.floor(val/((10^((i-1)*3))/100))/(100)..suffixes[i]
		end
	end
end

local function convert(n)
	local text = tostring(format(n))
	return text
end

local function gostergeler()
	plr.PlayerGui:WaitForChild("buttonsUI").mainFrame.mainFrame.CashGui.CashText.Text = "$"..convert(plr:WaitForChild("leaderstats"):WaitForChild("Cash").Value).."+"
	if plr:WaitForChild("tycoonBase").Value ~= nil then
		wait(0.5)
		for i,button in pairs(plr:WaitForChild("tycoonBase").Value.Buttons:GetChildren()) do
			if button:IsA("Model") and button.buttonSettings:FindFirstChild("Product") == nil and button.buttonSettings:FindFirstChild("gpass") == nil  and button.PrimaryPart.Transparency == 0 and button.PrimaryPart.CanCollide == true and plr:WaitForChild("leaderstats"):WaitForChild("Cash").Value >= button.buttonSettings.Price.Value then
				if button:FindFirstChild("buyThisModel") == nil then
					local clone = script.buyThisModel:Clone()
					clone:SetPrimaryPartCFrame(CFrame.new(button.PrimaryPart.CFrame.X,button.PrimaryPart.CFrame.Y+2,button.PrimaryPart.CFrame.Z))
					clone.Parent = button
					clone.AnimationController:LoadAnimation(script.buyModelAnimation):Play()
				end	
			else
				if button:FindFirstChild("buyThisModel") then
					button:FindFirstChild("buyThisModel"):Destroy()
				end
			end
		end
	end
end

plr:WaitForChild("leaderstats"):WaitForChild("Cash"):GetPropertyChangedSignal("Value"):Connect(function()
	gostergeler()
end)

repeat wait() until plr.Character ~= nil
repeat wait() until plr.Character:FindFirstChild("HumanoidRootPart") ~= nil

repeat
	for i,v in pairs(workspace:WaitForChild("Tycoon"):GetChildren()) do
		if v:IsA("Folder") then
			if v.Properties.Owner.Value == nil then
				local beam = workspace:WaitForChild("Beams"):FindFirstChild(v.Name)
				beam.Attachment1 = plr.Character:FindFirstChild("HumanoidRootPart").RootAttachment
			else
				local beam = workspace:WaitForChild("Beams"):FindFirstChild(v.Name)
				beam.Attachment1 = nil
			end
		end
	end
	wait()
until plr:WaitForChild("tycoonBase").Value ~= nil
	
for i,v in pairs(workspace:WaitForChild("Beams"):GetChildren()) do
	if v:IsA("Beam") then
		v.Attachment1 = nil
	end
end

Try this.

local Character = plr.Character or plr.CharacterAdded:Wait()

repeat wait() until Character ~= nil
repeat wait() until Character:FindFirstChild("HumanoidRootPart") ~= nil

repeat
	for i,v in pairs(workspace:WaitForChild("Tycoon"):GetChildren()) do
		if v:IsA("Folder") then
			if v.Properties.Owner.Value == nil then
				local beam = workspace:WaitForChild("Beams"):FindFirstChild(v.Name)
				beam.Attachment1 = Character:FindFirstChild("HumanoidRootPart").RootAttachment
			else
				local beam = workspace:WaitForChild("Beams"):FindFirstChild(v.Name)
				beam.Attachment1 = nil
			end
		end
	end
	wait()
until plr:WaitForChild("tycoonBase").Value ~= nil

for i,v in pairs(workspace:WaitForChild("Beams"):GetChildren()) do
	if v:IsA("Beam") then
		v.Attachment1 = nil
	end
end

still is showing the same error :frowning:

1 Like

To my knowledge, attempt to index nil with “” means that the path to that specific thing, in your code, “attachment1”, cannot be found. Try checking the path to attachment1 on the line there.