I'm making a game, as lots do. I want to make a gate open when you talk to a guard, but you need to have 20 coins. I've tried doing this in my best ability but I cant get anything to work. This is my script: (Also, I'm a beginner to scripting, so if it looks messy than you know why)
script.Parent.MouseButton1Click:Connect(function() script.Parent.Click:Play() local Click = script.Parent.MouseButton1Click script.Parent.Parent.Visible = false game.Workspace.Guard.Head.ProximityPrompt.ActionText = "Bring Coins" game.Workspace.Guard.Head.ProximityPrompt.Enabled = true script.Parent.Parent.Dialogue.Text = "Placeholder" script.Parent.Parent.Dialogue2.Text = "Where are the coins?" local player = game.Players:GetPlayerFromCharacter() if player.leaderstats.Coins.Value == 20 then game.StarterGui.Dialogue.WesternCitizens.GuardOpenningDialogue.Background.Dialogue2 = "Oh, you have what I need! Go on through.!" end end) game.Workspace.Map.Gates.DesertGate:Destroy()
Is there any help I could get with this?
I'm not exactly sure what is wrong with this script, it could use more information in the question.
Maybe it is because you have that the coins must be 20. Do you want them to be exactly 20, or 20 or over?
You could also try making all of your objects be variables. It would make your code easier to read and faster to write. You can also use that to test that they are working.
So instead of: ``script.Parent.MouseButton1Click:Connect(function() do:
part = script.Parent part.MouseButton1Click:Connect(function()
Then add a print statement to test if it is working:
part = script.Parent if part then print("Part found") end
That way you know if your part was found. You can make separate variables for all your parts, like the guard, the guard's head, whatever part script.Parent is, etc.
One way to figure out what is working is to do print statements like that, and the output also has error messages of its own. Use those to find out was is wrong.
I'm assuming that you created the coins in the leaderboard elsewhere (leaderstats.Coins), if not, then that might be your problem.
What exactly is going on, is your script just not doing anything, or is the wall disappearing no matter what happens? Because it looks like from what I can see here, that it is:
Checking for the clicked event
Running your function if clicked
Then it is destroying the gate
From what I can see, it seems that you should put your code to destroy the gate inside the 'if coins == 20' statement.
I think you also need to make a variable for your player's character, and put it in the brackets of your 'local player = game.Players:GetPlayerFromCharacter()'
As I said before, i need more information to know for sure what is wrong with it, and what is happening when you test it. Use the print statements and output to figure out what is going on.
Good luck! :)