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

this value based tool giving script only functions in studio?

Asked by
Clorize 31
5 years ago
Edited 5 years ago

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)
0
localscript or server? vissequ 105 — 5y
0
local script Clorize 31 — 5y
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? vissequ 105 — 5y
0
server**** Clorize 31 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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!

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 Clorize 31 — 5y
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) Clorize 31 — 5y
0
i realized that "game.Players.LocalPlayer" by itself does not function as well as instead defining it Clorize 31 — 5y
0
okay, i tried what you advised and, like before this question, the script only properly functions in studio testing Clorize 31 — 5y
View all comments (2 more)
0
im actually not sure how, but it worked, i think it's cuz of u Clorize 31 — 5y
0
tried again, didnt work, possibly cuz i just tested in studio Clorize 31 — 5y
Ad
Log in to vote
0
Answered by
Clorize 31
5 years ago
Edited 5 years ago

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]

Answer this question