ContextActionService:BindAction can only be called from a local script

I was creating a tycoon game, when I stubled across this error
image

It started when I created the tycoon game, but I thought nothing of it until right now.
Because when I inserted a button, made the model, I placed the Button in this folder
image

Then I placed the model in this folder.
image

So, inside the button there are 3 values.
Dependancy, Item and the Price.
What the Dependancy does is if you buy an item, then that button would appear, so its not just a load of buttons everywhere.

In the items folder, you would put the name of the model, ex: Dropper1.

The price is what you would expect, obviously it is the price of the item.

Those are the 3 main values, in every button.

So, my problem is that when you spawn in, either the model or the button is there.

Those items were supposed to be in the game later on.
And I’m pretty sure it’s not with the dependancy because i checked those items, and they were fine.
This is the main script located in the “Scripts” folder.

Blockquote— Variables —
local TycoonModel = script.Parent.Parent
local Items = {}
local BoughtItems = TycoonModel:FindFirstChild(“BoughtItems”)
local Buttons = TycoonModel:FindFirstChild(“Buttons”)
local DropperParts TycoonModel:FindFirstChild(“DropperParts”)
local MainItems = TycoonModel:FindFirstChild(“MainItems”)
local Scripts = TycoonModel:FindFirstChild(“Scripts”)
local Values = TycoonModel:FindFirstChild(“Values”)
— Owner Functions —
MainItems.OwnerDoor.MainDoor.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild(“Humanoid”) and Values.OwnerValue.Value == nil then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Player:FindFirstChild(“OwnsTycoon”).Value == false then
Values.OwnerValue.Value = Player
Player:FindFirstChild(“OwnsTycoon”).Value = true
MainItems.OwnerDoor.MainDoor.SurfaceGui.TextLabel.Text = tostring(Values.OwnerValue.Value)…" Tycoon"
end
end
end)
— Buying Functions —
for i,v in pairs(Buttons:GetChildren()) do
local NewItem = BoughtItems:FindFirstChild(v.Item.Value)
if NewItem ~= nil then
Items[NewItem.Name] = NewItem:Clone()
NewItem:Destroy()
else
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
v.ButtonPart.BillboardGui.Frame.Visible = false
end
if v:FindFirstChild(“Dependency”) then
coroutine.resume(coroutine.create(function()
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
v.ButtonPart.BillboardGui.Frame.Visible = false
if BoughtItems:WaitForChild(v.Dependency.Value, 100000) then
v.ButtonPart.Transparency = 0
v.ButtonPart.CanCollide = true
v.ButtonPart.BillboardGui.Frame.Visible = true
end
end))
end
v.ButtonPart.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild(“Humanoid”) then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Values.OwnerValue.Value == Player then
if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then
if Player:WaitForChild(“leaderstats”).Cash.Value >= v.Price.Value then
Player.leaderstats.Cash.Value -= v.Price.Value
Items[v.Item.Value].Parent = BoughtItems
v:Destroy()
end
end
end
end
end)
end
— Cash Functions —
local Debounce = false
MainItems.CashButton.ButtonPart.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild(“Humanoid”) then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Values.OwnerValue.Value == Player then
if Debounce == false then
Debounce = true
if game:GetService(“MarketplaceService”):UserOwnsGamePassAsync(Player.UserId,24922437) then
Player:WaitForChild(“leaderstats”).Cash.Value += Values.CashValue.Value * 2
wait()
Values.CashValue.Value = 0
wait(1)
Debounce = false
else
Player:WaitForChild(“leaderstats”).Cash.Value += Values.CashValue.Value
wait()
Values.CashValue.Value = 0
wait(1)
Debounce = false
end
end
end
end
end)
while wait() do
MainItems.CashButton.ScreenPart.SurfaceGui.TextLabel.Text = Values.CashValue.Value
end

There are more folders called:
Mainitems
Values

The Mainitems folder works like this:
If you insert a Model inside of the folder, then you will spawn with it in your tycoon.

The values folder, is where all of the values are stored.

There is also a script called “leaderstats”
Located in ServerScriptService.
This is the script.

Blockquotegame.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new(“Folder”, Player)
leaderstats.Name = “leaderstats”
local Cash = Instance.new(“NumberValue”, leaderstats)
Cash.Name = “Cash”
Cash.Value = 0
local OwnsTycoon = Instance.new(“BoolValue”, Player)
OwnsTycoon.Name = “OwnsTycoon”
OwnsTycoon.Value = false
end)

If you need any more information, please tell me.

As the error says, you can only use ContextActionService from local scripts. Not sure what exactly you need.

1 Like

I tried changing it to a local script, the error still occours.

And it also breaks the tycoon.

Your local script is in workspace, and it can’t run there.

Do I put the scripts folder in server script service or somewhere else?

A local script should be either in starterpack, startergui, or starterplayerscripts.

alright, i will try.
if it works, thanks.

1 Like

it worked, the error is gone, but i used a tutorial to do this and it came up with an error that i dont know how to fix.
keep in mind i am a beginner scripter who started about a week ago.


Is the ‘OwnerDoor’ always in workspace? Or does it get cloned there?

Using WaitForChild() would be good if not.

Its in bought items, which is in a folder, which is in tycoon model, which is in workspace.

where do i put it? at the end?
sorry if im wasting your time its just i copied it from a tutorial

It seems to me that the script is using “OwnerDoor” before it exists. Meaning your script is executing before it is within workspace. This could be that you’re cloning it to workspace after, or another issue.

Try:

MainItems:WaitForChild("MainDoor")

Let me know if that resolves the problem.
Nil = non-existant.

Try print(MainItems.OwnerDoor.MainDoor.Name) and see if it’s the problem of your pathing. If that errors use WaitForChild()

do i just delete that line and paste it in?

Yeah, exactly that. Let me know.

MainItems:WaitForChild("OwnerDoor", 1):WaitForChild("MainDoor", 1).Touched:Connect(function(hit)
--code here
end)

This should (also) work if your pathing’s correct

It fixed that error, now there is annother
image

Can we see what exactly you wrote?