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

Why does my tool clone script keep giving me a bunch of clones?

This is pretty hard to explain but I made a tool giver gui that clones a tool that I put in a folder in server storage. Although, it doesn't give me just 1 clone which is what I want, it gives me a bunch of clones. To be precise, the amount of clones that I get is the same amount of people there are in a server. If I'm alone in a server, then it works fine. I honestly don't know how to fix this. Here is my code if you're wondering.

--the server sided script
local RemoteEvent = game.ReplicatedStorage.RemoteEvent --find the remote event
local tool = game.ServerStorage.Tools.Lightsaber 

RemoteEvent.OnServerEvent:Connect(function(player)
	
local toolclone = tool:Clone()
toolclone.Parent = player.Backpack
end)

and the client sided script

--the client sided script
script.Parent.MouseButton1Down:Connect(function(player)
	local RemoteEvent = game.ReplicatedStorage.RemoteEvent
  	 RemoteEvent:FireServer()
end)

Any help is appreciated!

1 answer

✓ Accepted answer

All you need to do is adjust the server-sided script to this. If it comes up with an error please let me know! Otherwise, upvote my answer :)

--the server sided script
	local RemoteEvent = game.ReplicatedStorage.RemoteEvent --find the remote event
	local tool = game.ServerStorage.Tools.Lightsaber
	 
	RemoteEvent.OnServerEvent:Connect(function(player)

	if player.Backpack:FindFirstChild("Lightsaber") then
	else
	local toolclone = tool:Clone()
	toolclone.Parent = player.Backpack
	end
end)

3 comments

0

This should work, but you wrote this pretty badly. Instead of doing an if else and making the first statement empty, just do: 'if not player.Backpack:FindFirstChild("Lightsaber")'.                                                                                      P.S. Also, indentation!

0

It's not supposed to look pretty, it's just supposed to work. But thank you for the correction!

0

Thanks so much! It works perfectly now!

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