I need help with my friends game we both work on it together and we are trying to make game codes like in sims where u can redeem them for stuff. i have looked on the wiki but there are no tutorials or anything for it so i thought u could help me. also which script i use local or reg
I would start by making a folder that has the tools inside then start making the gui that gives the weapon. So I would do this.
This would be the button script in your gui (specifically the submit code button)
01 | -- Make sure its a local script lol |
02 |
03 | local code = script.Parent.Parent.CodeBox |
04 | local give = game.ReplicatedStorage.giveTool |
05 |
06 | script.Parent.MouseButton 1 Click:Connect( function () |
07 | if code.Text = = "code" then -- if the input is code then it will fire the event |
08 | give:FireServer() |
09 | else |
10 | print ( "incorrect code!" ) |
11 | end |
12 | end ) |
This will be the event
1 | -- Put this in serverscriptservice |
2 |
3 | local give = game.ReplicatedStorage.giveTool |
4 |
5 | give.OnServerEvent:Connect( function (plr) |
6 | local tool = game.Lighting.tools.Tool |
7 |
8 | tool:Clone().Parent = plr.Backpack |
9 | end ) |
This for a GUI in specific. In the gui have a textbox and a textbutton at the ready. Then just make a local script with this and put it in the gui. Then put the tool you want to give in lighting.
01 | local tool 1 = game.Lighting.Tool 1 |
02 | local tool 2 = game.Lighting.Tool 2 |
03 | local button = script.Parent.TextButton |
04 | local textBox = script.Parent.TextBox |
05 | local player = game.Players.LocalPlayer |
06 |
07 | button.MouseButton 1 Click:Connect ( function () |
08 | if textBox.Text = = "Put Code You Want Here" then |
09 | tool 1 :Clone ().Parent = player.Backpack |
10 | elseif textBox.Text = = "Another code here" then |
11 | tool 2 :Clone ().Parent = player.Backpack |
12 | end |
13 | end ) |
ty Uloamis for the answer this really helps