Need help with a steal mechanism script

Hi guys i really need help with my game.
Basically i am creating a game that has 2 teams: thieves and kingdom. And basically i want to make a game where the thieves need to steal 750 gold bars from the kingdom, and the kingdom team needs to protect the kingdom for 3 minutes (the duration of one round), i was making it so you could steal candles, jars, (those are made of gold, and then you would have to melt them on a lava thing) and even open chests that could have 5-20 gold bars inside them. But there is a problem, when i was making the steal mechanism, i could not get the candles (as a tool), nor get the gold from the chest. You can only steal those if you are playing on the “thieves” team, but the game seems to not understand the script, i don’t know what. Also, sorry for the long text.

Here is the chest script:

local chest = script.Parent
local randomCons = math.random(5, 20)
local opened = false
if opened == false then
local h = hit.Parent:FindFirstChildWhichIsA(“Humanoid”)
if h then
local plr = game.Players:GetPlayerFromCharacter(h.Parent)
if plr.Team == game.Teams.Robbers then
plr.leaderstats.Gold.Value = plr.leaderstats.Gold.Value + randomCons
randomCons = math.random(5, 20)
opened = true
ignore the “robbers” name, i only got to know the difference a few minutes ago. (i’m not a native english speaker)

and here is the candle script:

local candle = script.Parent.Candle

if plr.Team == game.Teams.Robbers then
print(plr.Name… " got a candle.")
local candle2 = game.ReplicatedStorage.Candle
candle2:Clone().Parent = plr.Backpack

I tried changing to a local script, but it didn’t work. I also tried creating a “robberPlayer” boolValue on the player, but the script also seemed to not know about it’s existence, it was something like this:

[…] → pretty much the same thing as before
local robberPlayer = plr:FindFirstChild(“robberPlayer”)
if robberPlayer then
print(plr.Name… " got a candle.")
local candle2 = game.ReplicatedStorage.Candle
candle2:Clone().Parent = plr.Backpack

Please help guys.

If it’s not working because it is only occuring once, it is because you set ‘opened’ as true. Because it is a server script, it will only work once for the whole server.

As for your candle script, try using:


Make sure both of your scripts are server scripts!

1 Like

Also, when concatenating, you don’t use 3 periods, only 2

Sorry, i forgot to specify the problem. The “Opened” thing is intentional, the problem is that when i tested, i didn’t get gold at all. The game does not know my team, i triend inserting a “Print(” on the script, and it printed “neutral” even though i was on the “thieves” team, so, because of this, i cannot get the gold. As for the second problem (the candles and the jars), it’s pretty much the same thing, the game does not identify my team, but thanks for suggesting the “Triggered” function, i think it works better than the “PromptButtonHoldEnded” one.

In your script it says that the required team to get these items are the robbers team

I was referring to it was the “thieves” because i was gonna change it soon, sorry for the unnecessary confusion, but yeah, currently, the name is “robbers”, i’m changing it real quick.

That is probably your issue then
You need to be referencing the right thing or else the program has no idea what you’re trying to achieve

Sorry, i meant that i was referring to the team as “thieves” here, on the conversation, but “robbers” is the name of the team, ingame.

From my eye, your script looks fine
Are you getting any errors in your output?

but why is it “Script.Parent:Destroy()” if you could just put “script:Destroy()”?
or else just put script.parent:destroy() if you want

wait no dont do this lol 1231232313

In your candle script does the player name print out?

Make sure to remove the extra period in your concatenation

It’s because the script is located on the candle. The candle is the script.parent, and when the player gets the candle (as a tool), it has to disappear (as an object).


script.parent:Destroy == you will destroy the tool
do script:Destroy so it wont “Destroy” the tool and yes the script
did u get it ?

hes not destroying the tool, the variable name is the parent of the proximity prompt part

I can’t really see my output because it’s kinda glitched but from what i remember, i tried doing this, to see if the problem was the script not knowing who the player is and… well it printed the player’s name.

that make sense… i thought it was located on the tool…

oh wait nvm sorry lol AA 30 LETERS

Can you send a video of you activating the proximity prompt & touching the part to gain gold?

Make sure your output and leaderboard is visible too

If you cant get your output open thats fine