Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
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

Log in to vote
0
Answered by
INOOBE_YT 387 Moderation Voter
7 years ago

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.

Ad
Log in to vote
0
Answered by 7 years ago

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

0
so where do i need to put the script then? bramieboy241 -19 — 7y
1
somewhere WHERE THE CHARACTER CAN TOUCH hiimgoodpack 2009 — 7y
Log in to vote
0
Answered by 7 years ago

Your problem is that Touched isn't a valid member of ServerStorage. Meaning, you cannot touch the service ServerStorage. The Touchedevent 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 Touchedevent here. Please accept my answer if this helped you in any way.

Log in to vote
0
Answered by 7 years ago

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

Answer this question