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

Why is this odd thing happening with cloning?

Asked by 2 years 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:

01local player = game.Players.LocalPlayer
02local storage = game:GetService("ReplicatedStorage")
03local bottle = storage:WaitForChild("Fast")
04local backpack = player.Backpack
05 
06 
07script.Parent.MouseButton1Click:Connect(function()
08    if player.leaderstats.Sips.Value >= 30 then
09        player.leaderstats.Sips.Value -= 30
10        local bottleClone = bottle:Clone()
11        bottleClone.Parent = backpack
12    end
13end)

This is the Tool's script:

01local tool = script.Parent
02 
03local canClick = true
04 
05 
06 
07local function onClick()
08 
09    if canClick then
10 
11        canClick = false
12 
13        local str = Instance.new("StringValue")
14 
15        str.Name = "toolanim"
View all 35 lines...

1 answer

Log in to vote
2
Answered by 2 years ago
Edited 2 years 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:
1local button = script.Parent
2local Rep = game.ReplicatedStorage
3 
4button.MouseButton1Click:Connect(function()
5    Rep.RemoteEvent:FireServer(game.Players.LocalPlayer)
6    Rep.RemoteEvent:FireServer("Thing") ---This will help the ReplicatedStorage what tool you need
7end)
  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:

01local event = Rep.RemoteEvent
02local descendants = Rep.Weapons:GetDescendants()
03 
04local function giveTools(player, toolsType)
05    for index, descendant in pairs(descendants) do
06        if toolsType == "Thing" then
07            if descendant.Name == "Item Here" or descendant.Name == "Item here" then
08                local weaponsToGive = descendant:Clone()
09                weaponsToGive.Parent = player.Backpack
10            end
11        end
12    end
13end
14 
15event.OnServerEvent:Connect(giveTools, toolsType)

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

01local event = Rep.RemoteEvent
02local descendants = Rep.Weapons:GetDescendants()
03 
04local function giveTools(player, toolsType)
05    for index, descendant in pairs(descendants) do
06        if toolsType == "Thing" then
07            if descendant.Name == "Your already dead car" then
08                local weaponsToGive = descendant:Clone()
09                weaponsToGive.Parent = player.Backpack
10            end
11        end
12    end
13end
14 
15event.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