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

Tools breaking when moved from ReplicatedStorage to StarterGear?

Asked by 6 years ago

I made this script that gives a player an item when bought with in-game currency. The way it works is when the player has enough coins and clicks the "Buy" button the game clones a tool from ReplicatedStorage to the players StarterGear, backpack.

01local player = game.Players.LocalPlayer
02local leaderboard = player:WaitForChild("leaderstats")
03local button = script.Parent
04local price = button:WaitForChild("Price")
05local item = button:WaitForChild("ItemName")
06local rs = game:GetService("ReplicatedStorage")
07 
08button.MouseButton1Click:connect(function()
09    if leaderboard.Coins.Value >= price.Value then
10        leaderboard.Coins.Value = leaderboard.Coins.Value - price.Value
11        local item = rs:WaitForChild(item.Value)
12        item:Clone().Parent = player.StarterGear
13        item:Clone().Parent = player.Backpack
14    end
15end)
16 
17while wait() do
18    button.image = item.Value.." - "..price.Value
19end

For some reason when the tool is moved the animations in the tool stop working. Here is the Animations script:

01local function WaitForChild(parent, childName)
02    while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
03    return parent[childName]
04end
05 
06local Tool = script.Parent
07 
08local Animations = {}
09local MyHumanoid
10local MyCharacter
11 
12 
13local function PlayAnimation(animationName)
14    if Animations[animationName] then
15        Animations[animationName]:Play()
View all 63 lines...

If anyone knows why the animations break when the tool is moved to StarterGear it will help me a ton. Thanks!

0
(Also just wanted to add. When I test it out in Studio it works but not in game. And yes the Animations Script and the Purchase Script are Local) tawk1215 47 — 6y
0
maybe try refreshing the script, by setting the Disabled to true then wait() to false User#23365 30 — 6y
0
and also why it doesn't work online is probably, because of FE, which has a bunch of remote events and stuff User#23365 30 — 6y
0
and u cant turn it off User#23365 30 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

I think it’s not working because you’re cloning the tool locally. If you clone locally, the whole tool breaks, and other players can’t see you holding the tool. Instead, you should use a remote event and clone the tool in a server (normal) script.

Here is what you’d do :

Local script

01local player = game.Players.LocalPlayer
02local leaderboard = player:WaitForChild("leaderstats")
03local button = script.Parent
04local price = button:WaitForChild("Price")
05local item = button:WaitForChild("ItemName")
06local rs = game:GetService("ReplicatedStorage")
07local remoteevent = rs:WaitForChild('RemoteEvent') -- Add a remote event into ReplicatedStorage
08 
09button.MouseButton1Click:Connect(function()
10    if leaderboard.Coins.Value >= price.Value then
11        leaderboard.Coins.Value = leaderboard.Coins.Value - price.Value
12        local item = rs:WaitForChild(item.Value)
13        remoteevent:FireServer(item)
14    end
15end)
16 
17while wait() do
18    button.Image = item.Value.." - "..price.Value
19end

Server script in ServerScriptService

1local RS = game:GetService('ReplicatedStorage')
2local RemoteEvent = RS:WaitForChild('RemoteEvent')
3 
4RemoteEvent.OnServerEvent:Connect(function(plr, item)
5    item:Clone().Parent = plr.Backpack
6    item:Clone().Parent = plr.StarterGear
7end)

Hope this helped!

0
It works! It also helped me out a ton! Thank you so much! tawk1215 47 — 6y
Ad

Answer this question