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?
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.
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