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

Why does my script only work in play solo but when I play with roblox player?

Asked by 9 years ago

Here's my script v v v It always work when I play solo but NEVER when I try playing with roblox player. :/ It's suppose to replace only the shirt of the player when he/she touches the block...

Platform = script.Parent

Platform.Touched:connect(function(hit)
    local h = hit.Parent
    if h.ClassName ~= "Model" then
        return nil
    elseif h.ClassName == "Model" then
        h.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=65387140"
    end
end)
0
If possible, do give me a fixed version of the script :/ rizqullah30 5 — 9y

2 answers

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

Your method of checking to see if a Player hit your 'Platform' is easily broken. As well, the character may or may not have a Shirt object when you try to access it, you'll have to add one in if they don't. Try this code instead:

Platform = script.Parent

Platform.Touched:connect(function(hit)
    local h = hit.Parent
    if not Game.Players:GetPlayerFromCharacter(h) then return end
    if not h.Shirt then Instance.new("Shirt", h).Name = "Shirt" end
    h.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=65387140"
end)
Ad
Log in to vote
-1
Answered by 9 years ago

You took it from Free Modules I guess. What does output shows you?

0
Please do not submit an answer that is just a comment of the OP's question. There is a comment section just for that. (I know you can't use it yet, so just hold out until you get enough reputation that you can.) adark 5487 — 9y

Answer this question