Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Output makes no sense?

enabled = true

function onTouch()
	if enabled == true then
		enabled = false
		shell = game.ReplicatedStorage.Shell:Clone()
		shell.Parent = script.Parent.Parent
		shell.CFrame = script.Parent.Parent.Spawn1.CFrame
		shell2 = shell:Clone()
		shell2.Parent = script.Parent.Parent
		shell2.CFrame = script.Parent.Parent.Spawn2.CFrame
		wait(0.5)
		shell3 = shell2:Clone()
		shell3.Parent = script.Parent.Parent
		shell3.CFrame = script.Parent.Parent.Spawn1.CFrame
		shell4 = shell3:Clone()
		shell4.Parent = script.Parent.Parent
		shell4.CFrame = script.Parent.Parent.Spawn2.CFrame
		wait(1.5)
		while wait() do
			if shell.Value.Value == 25 then
				shell:Destroy()
			break
			elseif shell.Value.Value == 0 then
				shell:Destroy()
			end
		end
		while wait() do
			if shell2.Value.Value == 25 then
				shell2:Destroy()
			break
			elseif shell2.Value.Value == 0 then
				shell2:Destroy()
			end
		end
		wait(0.5)
		while wait() do
			if shell3.Value.Value == 25 then
				shell3:Destroy()
			break
			elseif shell3.Value.Value == 0 then
				shell3:Destroy()
			end
		end
		while wait() do
			if shell4.Value.Value == 25 then
				shell4:Destroy()
			break
			elseif shell4.Value.Value == 0 then
				shell4:Destroy()
			end
		end
		enabled = true
	end
end

script.Parent.Touched:connect(onTouch)

This script causes shells to roll down a hill and disappear after a set time. If a shell hits someone, the script will wait for the shell's script to execute before destroying it. The shell itself gradually decreases the player's health by 25, and the IntValue (named Value) in the shells keep track of when the player's health is successfully drained. The Value should hit 25, signalling the script that the script is done and that it's okay to destroy the shell. However, when the script is triggered, this shows up in the output:

--15:34:33.428 - Value is not a valid member of UnionOperation
--15:34:33.429 - Script 'Workspace.Shell Complex.Sensor.Script', Line 21
--15:34:33.429 - Stack End

What?! I checked the clones that the script spawns, and they do indeed have Values in them. Is the problem cause by the fact that the shells are unions? What's going on? The shells are named Shell, not UnionOperation.

2 answers

Is the value named 'Value'? Try changing it to 'BarrelValue' or something of that sort.

2 comments

0

I'm afraid this doesn't work.

0

Try shell:FindFirstChild('Value')

What is happening is that Lua thinks that shell.Value.Value is looking for a PROPERTY called Value. To fix this, rename it to something besides "Value" or do shell:findFirstChild("Value").Value

This discussion is preserved as it was. New answers, comments, and votes are closed.