Ad
Log in to vote
0

Why is this odd thing happening with cloning?

Asked by 14 days ago

I have made a tool, and when I test it out by putting it in StarterPack, it works as it should, but when I put it in ReplicatedStorage, and use a TextButton to 'buy' it, it gives me the tool, except it does not work. At first, I thought it was because the children weren't cloning, so I changed the script. I can see that the children are cloning because while testing I can press on the player's backpack and it's there in full. I have no idea why it doesn't work.

This is the Button script:

local player = game.Players.LocalPlayer
local storage = game:GetService("ReplicatedStorage")
local bottle = storage:WaitForChild("Fast")
local backpack = player.Backpack


script.Parent.MouseButton1Click:Connect(function()
    if player.leaderstats.Sips.Value >= 30 then
        player.leaderstats.Sips.Value -= 30
        local bottleClone = bottle:Clone()
        bottleClone.Parent = backpack
    end
end)

This is the Tool's script:

local tool = script.Parent

local canClick = true



local function onClick()

    if canClick then

        canClick = false

        local str = Instance.new("StringValue")

        str.Name = "toolanim"

        str.Value = "Slash" 

        str.Parent = tool

        local player = game.Players:FindFirstChild(tool.Parent.Name)

        player.leaderstats.Sips.Value = player.leaderstats.Sips.Value + 2

        wait(1)

        canClick = true

    end

end



tool.Activated:Connect(onClick)

1 answer

Log in to vote
2
Answered by 14 days ago
Edited 14 days ago

If Im correct, Its a local script thats causing the problem of your tools not functioning

the reason Is quite simple, whenever you press the Item giver, the local script will give you the Item. Don't be fooled though! as despite giving you the Item, It actually doesn't appear In the server side, you can check by play testing, pressing the button that gives you the tool, equip the tool, and lastly, go to test > then press the button: "Current: Client" (What the "Current: Client" does It that It lets you view both client and server side)

I encounter this before Ill share you how to fix It:

If you don't want to do the steps, use this free model I made: https://web.roblox.com/library/10957699247/Item-Giver-GUI

  1. Create a RemoteEvent In ReplicatedStorage
  2. Add In a local script In a button gui 3.Paste this script:
local button = script.Parent
local Rep = game.ReplicatedStorage

button.MouseButton1Click:Connect(function()
    Rep.RemoteEvent:FireServer(game.Players.LocalPlayer)
    Rep.RemoteEvent:FireServer("Thing") ---This will help the ReplicatedStorage what tool you need
end)
  1. Create a folder which has every Item you have (Folder must be In ReplicatedStorage and Items are In the folder)

  2. Create a script ServerScriptStorage

  3. Type this:

local event = Rep.RemoteEvent
local descendants = Rep.Weapons:GetDescendants()

local function giveTools(player, toolsType)
    for index, descendant in pairs(descendants) do
        if toolsType == "Thing" then
            if descendant.Name == "Item Here" or descendant.Name == "Item here" then
                local weaponsToGive = descendant:Clone()
                weaponsToGive.Parent = player.Backpack
            end
        end
    end
end

event.OnServerEvent:Connect(giveTools, toolsType)

The script above me gives you two Items, If you just want one do this:

local event = Rep.RemoteEvent
local descendants = Rep.Weapons:GetDescendants()

local function giveTools(player, toolsType)
    for index, descendant in pairs(descendants) do
        if toolsType == "Thing" then
            if descendant.Name == "Your already dead car" then
                local weaponsToGive = descendant:Clone()
                weaponsToGive.Parent = player.Backpack
            end
        end
    end
end

event.OnServerEvent:Connect(giveTools, toolsType)

And your done

If the answer doesn't work, Its due to me simply copying all the scripts In a random game I made

Ad

Answer this question