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

When i wanna test my tycoon i alway's get an error?

local Bank = script.Parent
local PartName = "Cash"
local Collector = game.Workspace.BramsTycoon.Essentials.MoneyCollector.Collector
local MoneyAmount = 0

Bank.Touched:connect(function(hit)
	if hit.ClassName == "Part" and hit.Name == PartName then
		hit:remove()
		Collector.Money.Value = Collector.Money.Value + MoneyAmount
	end
end)

local IntVal = Instance.new("IntValue")
IntVal.Name = "Cash"
IntVal.Parent = Collector
IntVal.Value = 0

the error is Touched is not a valid member of ServerStorage. Do i need to put this script somewhere else or is something wrong whit the script?

4 answers

✓ Accepted answer

Your script is in the ServerStorage. This is a service and services cannot have the .Touched event connected to them. To avoid this error, put the script inside of a part. If you still want to have the script in ServerStorage, then you could write:

local Bank = script.Parent
local PartName = "Cash"
local Collector = game.Workspace.BramsTycoon.Essentials.MoneyCollector.Collector
local MoneyAmount = 0

if Bank:IsA("BasePart") then
	Bank.Touched:connect(function(hit)
	    if hit.ClassName == "Part" and hit.Name == PartName then
	        hit:remove()
	        Collector.Money.Value = Collector.Money.Value + MoneyAmount
	    end
	end)

	local IntVal = Instance.new("IntValue")
	IntVal.Name = "Cash"
	IntVal.Parent = Collector
	IntVal.Value = 0
end

This just checks if Bank is a valid part to avoid the error.

You simply cannot touch ServerStorage, as it acts like it is not in the game.

2 comments

0

so where do i need to put the script then?

1

somewhere WHERE THE CHARACTER CAN TOUCH

Your problem is that Touched isn't a valid member of ServerStorage. Meaning, you cannot touch the service ServerStorage. The Touched event only works with BaseParts, because those are something that a player can actually interact with. Consider putting this script into a Part. Read more about the Touched event here. Please accept my answer if this helped you in any way.

move the script inside of the "Bank" part and it should work

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