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

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

Asked by
atmxe 17
3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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)

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! proqrammed 285 — 3y
0
It's not supposed to look pretty, it's just supposed to work. But thank you for the correction! SecretPax 20 — 3y
0
Thanks so much! It works perfectly now! atmxe 17 — 3y
Ad

Answer this question