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

this value based tool giving script only functions in studio?

just so you know i do have the tools in replicated storage and the script does give me the tool based on the value but only on studio (the new text editor is weird so i did not put any effort into fixing the messed up indenting) Edit: What an easy fix, the issue was that the tools weren't loading in time so i had to add "WaitForChild()" Edit2: That fix didn't actually work. Edit3: Replaced the respawn function with player.CharacterAdded

local replicatedStorage = game:GetService("ReplicatedStorage")

  

game.Players.PlayerAdded:Connect(function(player)

local class = Instance.new("StringValue",player)

class.Name = "Class"

class.Value = "Stick"

if class.Value == "Stick" then

wait(.1)

local clone = replicatedStorage.Stick:Clone()

clone.Parent = player.Backpack

elseif class.Value == "Axe" then

wait(.1)

local clone = replicatedStorage.Axe:Clone()

clone.Parent = player.Backpack

end

game.Workspace[player.Name].Humanoid.Died:Connect(function()

wait(5)

if class.Value == "Stick" then

wait(.1)

local clone = replicatedStorage.Stick:Clone()

clone.Parent = player.Backpack

elseif class.Value == "Axe" then

local clone = replicatedStorage.Axe:Clone()

clone.Parent = player.Backpack

end
end)
end)

4 comments

0

localscript or server?

0

local script

0

It won't replicate to the server because it's a local script. You are trying to create a value with a localscript and it is not appearing on the server, correct?

0

server****

2 answers

✓ Accepted answer

Answer

Hi. First of all, I hope you will succeed with your game. Now, to the errors you've made!

So you didn't actually make errors, only that the tools have no place to be stored in. What I usually do is add a folder into the player using Instance.new And putting tools into it. You could find an example from one of my projects in the "Code" section of this article

Code

This is how I set up my values:

local toolsFolder = Instance.new("Folder")
toolsFolder.Parent = game.Players.Localplayer
toolsFolder.Name = game.Players.Localplayer.Name

local class = Instance.new("StringValue")
class.Parent = toolsFolder
class.Name = "Class"
class.Value = "Stick"

Why use the code

The code matters because the game will sometimes get confused since the value is stored in all players. To prevent this, I named the folder whatever the player name is.

Grand Finale

Hope this helps! Please marked question as answered from this answer if this was helpful! If it wasn't helpful, comment on this in the next 24 hours and I might come back to help! Hope your game gets successful!

6 comments

0

just a small question: after writing the classtype (not the classes, for the Instance.new) can't you just put a coma then the parent you want to add it to

0

i was testing to see if it works,and i got this message (on line 3 for your code) 16:49:59.449 - ServerScriptService.ClassScript:5: bad argument #3 to 'Name' (string expected, got nil)

0

i realized that "game.Players.LocalPlayer" by itself does not function as well as instead defining it

0

okay, i tried what you advised and, like before this question, the script only properly functions in studio testing

0

im actually not sure how, but it worked, i think it's cuz of u

0

tried again, didnt work, possibly cuz i just tested in studio

The tools don't load in time when the script runs, to solve this add a "WaitForChild()" on the part where you are mentioning the tools Edit: use player.CharacterAdded instead of game.Workspace[player.Name]

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