Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My Class GUI Won't function with no error statements?

Asked by
BryanFehr 133
5 years ago

Hello, I've recently made a GUI with classes in it, for when the player joins the game, they'll have to select one of said classes to use in game, and after selection, the frame is destroyed. Why won't this function without error codes?

local primary = game.ServerStorage.AK47
local secondary = game.ServerStorage.Baretta
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function(click)
if script.Parent.MouseButton1Click == true then
   player.FindFirstChild("Backpack")
     primary:Clone()
     secondary:Clone()
    script.Parent.Parent:Destroy()
    end
end)

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

# Problems Here

There are a couple of problems with your code here, those being that :

  • mousebutton1click is an event, not a property
  • local scripts cannot access the server storage, as it can only be accessed by server sided scripts
  • you only cloned that objects and not parented them anywhere
  • you did nothing with the cloned guis, or the Backpack
  • FindFirstChild is a method, so you would have to use : instead of .
  • Cloning anything on the client is a very bad idea, for starters, it doesn't work with filtering enabled

# Solution

With that said, here is a fixed version

Local Script

```lua local RP = game:GetService("ReplicatedStorage") local remote = RP.RemoteEvent

script.Parent.MouseButton1Click:Connect(function() RP:FireServer() script.Parent.Parent:Destroy() end) ``` Server Script

```lua local RP = game:GetService("ReplicatedStorage") local remote = RP.RemoteEvent local primary = RP.AK47 local secondary = RP.Baretta

RP.OnServerEvent:Connect(function(plr) local p = primary:Clone() local s = secondary:Clone() p.Parent = plr.Backpack end) ```

# Hmm, that doesn't seem that safe

The scripts above do not really seem safe and rational to many people, and indeed, it isn't.

This is because, the client can too easily get multiples of the same tools simply by firing the remote multiple times.

To prevent this, you can simply use a boolean value to stop the client from simply firing the event multiple times to get multiple guns

# Other takeaways here

A couple of other things you should take away here are that:

  • Always make your scripts work with Filtering Enabled
  • Don't let the client have too much power, use sanity checks when needed and handle important stuff on the server when possible

Hopefully that helped!

0
Where would I put the ServerScript? As this is for a class GUI! BryanFehr 133 — 5y
0
The server script, and server scripts in general should go in Server Script Storage theking48989987 2147 — 5y
0
How would I make this function with more than once class? BryanFehr 133 — 5y
0
Stop it, he is not writing your entire game for you User#24403 69 — 5y
Ad

Answer this question