Cant get value from random item selector when selecting value

i have a code that assigning a random thing from a folder

local partvirus = script.Parent.Virus


script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent:FindFirstChild("Injected") then
		local char = hit.Parent
		
		local cln = Instance.new("BoolValue")
		cln.Parent = hit.Parent
		cln.Name = "Injected"
		
		if partvirus.Value == "V-B91N2" then
			local VirusServerStorage = game.ServerStorage.Viruses:FindFirstChild(partvirus)
			
			char.Head.Size = char.Head.Size + Vector3(1,1,1)
			wait(.5)
			char.Head.Size = char.Head.Size + Vector3(1,1,1)
			wait(.5)
			char.Head.Size = char.Head.Size + Vector3(1,1,1)
			wait(.5)
			char.Head.Size = char.Head.Size + Vector3(1,1,1)
			local cln = VirusServerStorage.SFX:Clone()
			cln.Parent = script.Parent
			cln.PlayOnRemove = true
			cln:Remove()
			char.Head:Remove()

		end
		
	end
end)

it errors with this , line 15
image

image

The values are string values

2 Likes

It’s because you changed it to a string, not an actual instance, which is why you can’t access it using .Value.

Fixed code:

local gasobject = script.Parent.Parent.GasObject
local db = false

script.Parent.ClickDetector.MouseClick:Connect(function(hit)
	if not db then
		local items = game.ServerStorage.Viruses:GetChildren()
		local randomItem = items[math.random(#items)]
		print(randomItem.Name)

		db = true

		script.Parent.Parent.GasInject.SFXDeploy.Playing = true
		script.Parent.Parent.GasInject.SFXDeploy.TimePosition = 0.01

		local cln = gasobject:Clone()
		cln.Size = Vector3.new(5, 21.5, 22)
		cln.Position = script.Parent.Parent.Robot.Torso.Position
		cln.Anchored = false
		cln.Virus.Value = randomItem.Value
		cln.Parent = script.Parent.Parent

		task.wait(3)
		script.Parent.Parent.GasInject.SFXDeploy.Playing = false

		db = false

		task.wait(1)
		cln:Destroy()
	end
end)
1 Like

i tried but it says the same error also this is virus folder i have

image

1 Like

Try this:

--//Services
local ServerStorage = game:GetService("ServerStorage")

--//Variables
local Viruses = ServerStorage.Viruses
local gasobject = script.Parent.Parent.GasObject

--//Controls
local debounce = false

--//Functions
script.Parent.ClickDetector.MouseClick:Connect(function(hit)
	if debounce then
		return
	end
	
	debounce = true
	
	local items = Viruses:GetChildren()
	local randomItem = items[Random.new():NextInteger(1, #items)]
	print(randomItem.Name)

	script.Parent.Parent.GasInject.SFXDeploy.Playing = true
	script.Parent.Parent.GasInject.SFXDeploy.TimePosition = 0.01

	local cln = gasobject:Clone()
	cln.Anchored = false
	cln.Size = Vector3.new(5, 21.5, 22)
	cln.Position = script.Parent.Parent.Robot.Torso.Position
	cln.Virus.Value = randomItem.Value
	cln.Parent = script.Parent.Parent

	task.wait(3)
	script.Parent.Parent.GasInject.SFXDeploy.Playing = false

	debounce = false

	task.wait(1)
	cln:Destroy()
end)
1 Like

wait i just noticed thats the wrong code

its actualyl this

local partvirus = script.Parent.Virus


script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent:FindFirstChild("Injected") then
		local char = hit.Parent
		
		local cln = Instance.new("BoolValue")
		cln.Parent = hit.Parent
		cln.Name = "Injected"
		
		if partvirus.Value == "V-B91N2" then
			local VirusServerStorage = game.ServerStorage.Viruses:FindFirstChild(partvirus)
			
			char.Head.Size = char.Head.Size + Vector3(1,1,1)
			wait(.5)
			char.Head.Size = char.Head.Size + Vector3(1,1,1)
			wait(.5)
			char.Head.Size = char.Head.Size + Vector3(1,1,1)
			wait(.5)
			char.Head.Size = char.Head.Size + Vector3(1,1,1)
			local cln = VirusServerStorage.SFX:Clone()
			cln.Parent = script.Parent
			cln.PlayOnRemove = true
			cln:Remove()
			char.Head:Remove()

		end
		
	end
end)

sorry about that

1 Like

What’s the error with this code again?

The error is the same as before 15 line

1 Like

Which line of your code errors?

Oh line 15 is the errorrrrrrrrrr

1 Like

Can you please be specific? Which code in the script is line 15 exactly?

This
image

1 Like

What is the error message?

gfdjkgdf

Found the error. It’s the code Vector3(1,1,1).

This is not how you construct Vector3 values. Use Vector3.new().

Also @hasoco please read the topic before asking any questions.

2 Likes

image

Try this:

--//Services
local ServerStorage = game:GetService("ServerStorage")

--//Variables
local Viruses = ServerStorage.Viruses
local partvirus = script.Parent.Virus

--//Functions
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent:FindFirstChild("Injected") then
		local char = hit.Parent

		local cln = Instance.new("BoolValue")
		cln.Parent = hit.Parent
		cln.Name = "Injected"

		if partvirus.Value == "V-B91N2" then
			local VirusServerStorage = Viruses:WaitForChild(partvirus.Name)
			
			for i = 1, 4 do
				char.Head.Size += Vector3.one
				task.wait(0.5)
			end
			
			local cln = VirusServerStorage.SFX:Clone()
			cln.PlayOnRemove = true
			cln.Parent = script.Parent
			
			cln:Destroy()
			char.Head:Destroy()
		end
	end
end)
2 Likes

I read the topic… I was asking about the new error message.

1 Like

it worked thank you guys for all the help though, i dont know why i keep forgetting .new when typing in vector

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.