Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

my class gui dosent give the guns how to fix?

im making a class based tf2 like game and im trying to give the guns when you press the class you want put it wont work how to fix?

script.Parent.MouseButton1Click:Connect(function(player)
	local Parent = player.Parent
		if game.Players:GetPlayerFromCharacter(Parent) then
		game.ReplicatedStorage.Minigun:Clone()
		game.ReplicatedStorage.Minigun.Parent = Parent.Backpack
	end
end

2 answers

The players backpack is just player.Backpack. And also the character thing is useless, because you do not need it. Also make sure that you are giving the gun on the server, not the client! I thought it was a click detector but after I saw the comments lol, but I fixed the code. If it is in a local script, you should use a event to connect the client to the server, and to get the player.

local event = game.ReplicatedStorage:WaitForChild('RemoteEvent') --replace with yours
script.Parent.MouseButton1Click:Connect(function()
        event:FireServer()
end

In a server script it should be

local event = game.ReplicatedStorage:WaitForChild('RemoteEvent') --replace with yours

local function giveTool(player)
	local gun = game.ReplicatedStorage.Minigun:Clone()
	gun.Parent = player.Backpack
end
event.OnServerEvent:Connect(giveTool)

Please accept my answer if your issue is solved, and let me know if you need any more help!

5 comments

0

i doesnt work

0

Use "gun.Parent = game.Players.LocalPlayer.Backpack".

0

You can't get the player from the MouseButton1Click event.

0

none of these work im using a local script in starter gui

0

fixed the issues srry i thought it was a click detector lol

Player isn't a parameter of MouseButton1Click, you can use LocalPlayer if this is in a local script.

If you need this to be run on the server you can simply use a RemoteEvent.

local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	-- Code
	local MinigunClone = game.ReplicatedStorage.Minigun:Clone()
	MinigunClone.Parent = Player.Backpack
end)

4 comments

0

this doesnt work either

0

Are you doing this in a local script or Server Script?

0

in starter gui

0

starter gui local script

This discussion is preserved as it was. New answers, comments, and votes are closed.