A working script stops working when I import it into another project

I made a simple script that displays something ( ui ) when I interact with a proximity prompt. It works, no problems in the output.
But when I import this script into another roblox studio project, I get an error in the output which is not logical because it should work.

here is the structure of my system, the proximity prompt in workspace :
image
and now the script to open the ui :


I tested this script and it worked, but when I imported it into another project it no longer worked and displayed this in the output, even though I had put in the right calls to find the proximity prompt. I don’t understand, I’m beginning to despair

if anyone has any ideas on how to solve this, you’re very welcome.

4 Likes

Maybe possibly try a waitforchild on ProximityPromtPart, for example:

local ProximityPart = game.Workspace.ShopModel:WaitForChild("ProximityPromptPart")

and use that variable to create the triggered function,

or maybe check if somehow proximitypromptpart is being deleted when you run the game? possibly you accidently set CanCollide to false and the part is falling through the world and being deleted?

3 Likes

Check if there are more objects in workspace that have the same name, use waitforchilds to safely get the proximity and make sure the script places are set correctly

2 Likes

As the two others said, use WaitForChild. If the script loads before the workspace (It’s in a Gui so I believe it does), then it may start running before what you’re trying to find exists.

(Though, if that’s the solution then it’s weird it works in one but not the other, maybe the order you add things to the workspace dictates the order they load in shrug)

2 Likes

thank you very much! it works great, it was very weird

I’m taking the liberty of sending you one last message about a similar problem. I used the “waitforchild” as you told me but it gives me an infinite yield and then when I click on the “buy” button, nothing happens.

that only happens because “leaderstats” doesn’t exist

but i have a leaderstats on serverscriptservice

does the script actually create a leaderstats folder?


yes

you didnt add .LocalPlayer, change it to

local leaderstats = player.LocalPlayer:WaitForChild("leaderstats")

and I also recommend actually using the values you create so also change local dollars to this

local dollars = leaderstats.Dollars

it still doesn’t work :confused:

why are you using a server script for that, use a local script with a remote event for what your trying to achieve (also at this point just make another topic so this already solved topic can close)

but don’t you have a solution? because I’d like to keep a serverscript

you can’t get local player from a server script

this is weird because it works on another projects

While there is a better way to do it

A solution to your problem would to be using parenting.

Because the script is inside startergui, everything inside startergui goes inside the playergui (The playergui is inside the player) when a player joins, to get the individual player, you would just have to do this:

local Player = script.parent.parent.parent.parent.parent.parent.parent

that should be a solution to your code unless i missed or added a extra .parent

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.