Help getting a tool into player inventory (via script)

I suck at scripting so I need help. Sorry for actual embarrassing dum mistakes :flushed:

Basically, I’m making a shop system where the player goes into a store and interacts with an item’s proximity prompt. If they have the amount of money that is needed to purchase the item, they get it in their inventory as a tool and the mesh is destroyed. What players see and interact with is just a mesh. A sword is given to them, a tool. But this doesn’t work.

  • The cash system was made using leaderstats

Here is the sad script

image

sword1 = the mesh sword
sword2 = the tool sword

When running this script nothing came in f9 when i playtested. Help is appreciated thanks

5 Likes

what specifically doesn’t work? Also, is this a script or a local script? Local scripts cannot change datastore values.
I assume there are no errors either. In the future, please avoid using screenshots of code and instead paste your code into a code block.
Did any of the print statements appear?

2 Likes

Not sure what doesn’t work, nothing came in f9/output. It’s a script.

I can edit the post, I just forgot how to put it in the block on DevForum

2 Likes

What type of script is this? Server or Local script? And is there any errors on the output?

3 Likes

So absolutely nothing works? Try adding a print statement at the start of the onPromptTriggered function.

2 Likes

I just did, nothing showed in output. I know I referenced it correctly and have put the PP where it should be.

2 Likes

Is the script enabled? Absolutely nothing prints even when you put it at the start of the function?
Perhaps try using an anonymous function instead?

2 Likes

yes and yes

Sorry, how would I go about that?

1 Like

Add a print at the start of the script (line 1) and see if it prints

1 Like

an anonymous function is when you create a new function on the spot

ProximityPrompt.Triggered:Connect(function(plr)
    -- your code
end)
1 Like

Oh ok. But in the function you also need to reference plr so not sure if it works. But I can try that

1 Like

image

1 Like

You can add plr “inside” the function, like this:

ProximityPrompt.Triggered:Connect(function(plr)
    -- your code
end)
2 Likes

Maybe script.Parent isn’t a proximity prompt. Try checking that.

2 Likes

Oh ok, I used to always get the red underline whenever I tried it. Must’ve been my mistake. I’ll try it and I’ll see if it works, thank you!

1 Like

It’d error if it wasn’t since Triggered is an event exclusive to ProximityPrompts.
I feel like the wrong Proximity Prompt is being referenced here…

1 Like

image
This is the mesh sword with the script, it’s properly being referenced. And it still doesn’t work…

Perhaps the code:

  • sword2.Parent = plr.Character

isn’t the right way to get the tool inside the inventory? But then again… The sword is not destroyed when the PP is interacted with (and when I have enough money) so that’s weird too

1 Like

Is the ProximityPrompt’s Enabled property actually enabled?

1 Like

The script still doesn’t print when the proximity prompt is triggered. So it can’t be that.

Uh, script.Parent isn’t the proximity prompt, it’s the sword. You want script.Parent.ProximityPrompt.

1 Like