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
chest.KeyHole.Touched:Connect(function(hit)
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
end
end
end
end)
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
candle.Obtain.PromptButtonHoldEnded:Connect(function(plr)
if plr.Team == game.Teams.Robbers then
print(plr.Name⌠" got a candle.")
local candle2 = game.ReplicatedStorage.Candle
candle2:Clone().Parent = plr.Backpack
script.Parent:Destroy()
end
end)
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
script.Parent:Destroy()
end
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:
candle.Obtain.Triggered:Connect(function(plr))
--code
Make sure both of your scripts are server scripts!
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(plr.team)â 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).
WAIT
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