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

This only works in studio? [Not answered]

Asked by
wackem 50
9 years ago

I'm trying to make one of those barista uniform things for a client and this seems to only work in studio:

local b = script.Parent
local plr = b.Parent.Parent.Parent.Parent
plr.CharacterAdded:wait()
local char = plr.Character
local shirtID = 169511223
local pantID = 0


b.MouseButton1Click:connect(function()
    if char:FindFirstChild("Shirt") then
        local v = char:FindFirstChild("Shirt")
        v.ShirtTemplate = "http://www.roblox.com/asset/?id="..shirtID
    else
        local s = Instance.new("Shirt", char)
        s.ShirtTemplate = "http://www.roblox.com/asset/?id="..shirtID
        s.Name = "Shirt"
    end
 end)

b.MouseButton1Click:connect(function()
    if char:FindFirstChild("Pants") then
        local v = char:FindFirstChild("Pants")
        v.PantsTemplate = "http://www.roblox.com/asset/?id="..pantID
    else
        local s = Instance.new("Pants", char)
        s.PantsTemplate = "http://www.roblox.com/asset/?id="..pantID
        s.Name = "Pants"
    end
 end)

I do not know why

0
Sometimes that script will run before the player loads, so add `WaitForChild`. woodengop 1134 — 9y
0
where? wackem 50 — 9y
0
Your Variables of course. woodengop 1134 — 9y
0
@TheContinentofEurope You may want to explain which Variables exactly; He could misinterpret what you mean, and type for the Variables (for example, line 2) as 'b:WaitforChild("Parent"):WaitForChild("Parent"):WaitForChild("Parent")' and so on (and may do it with the Player's Character as well. Just a bit of a heads up. :P TheeDeathCaster 2368 — 9y
View all comments (6 more)
0
The character is already being waited for with plr.CharacterAdded:wait() if that's where you want me to put it. wackem 50 — 9y
0
@Hyphonated What isn't working exactly about the code? What is not working in Online mode for it? Where isn't it doing it's job (or purpose, in other words)? These Questions (information) are important so that we can give you a legitimate Answer, and so we can prepare to Answer your Question with high hopes. :) TheeDeathCaster 2368 — 9y
0
There are no errors, that's why I'm here. I don't know where it's not doing it's job. It works in studio but not online. wackem 50 — 9y
0
Add a wait(1) before the first line. The client scripts sometimes will load and run before the player object is initially created initially as TheContinentofEurope explained. FearMeIAmLag 1161 — 9y
0
even then it does not work wackem 50 — 9y
0
If there is no errors, it usually means the script is yielding. You may want to check your parenting on line 2 or add a repeat loop to yield until the variable plr is a player. Spongocardo 1991 — 9y

Answer this question