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

How to use avatar decals?

Asked by 6 years ago

I have a gui that when the spawn is touched, it prints the user's roblox avatar image, but the script isn't working. Help please.

function onTouched(hit)
    if hit.Parent:GetPlayerFromCharacter('Humanoid') then
        local userid = hit.Parent.UserId
        game.Workspace.LocalUserId.Value = userid
        wait(0.1)
        game.Workspace.join.SurfaceGui.ImageLabel.Image =('http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&Format=Png&userId='userid)
    end
end

script.Parent.Touched:connect(onTouched)

Thanks

1 answer

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

EDIT I answered too soon!

There's a few more things we need to change.

GetPlayerFromCharacter is a method of the Players service, not hit.Parent (that's the character). UserId is a property of the player, NOT the character. You pass in the string "Humanoid" whereas we need to pass in the parent of the object (say a leg or an arm) which is the character.

Here is the wiki article on player UserId's.

local players = game:GetService("Players")
function onTouched(hit)
   local player = players:GetPlayerFromCharacter(hit.Parent) 
    if player then -- This will only run if our player variable exists.
        local userid = player.UserId
        game.Workspace.LocalUserId.Value = userid
        wait(0.1)
        game.Workspace.join.SurfaceGui.ImageLabel.Image =('http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&Format=Png&userId='..userid)
    end
end

script.Parent.Touched:connect(onTouched)

In order to append or concatenate strings in lua you want to use the .. operator.

Here's how you do that with your code.

game.Workspace.join.SurfaceGui.ImageLabel.Image =('http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&Format=Png&userId='..userid)

Some examples.

print("my ".."name is ".."kools") -- my name is kools
local var = 3
print("# is "..var) -- # is 3
0
Thank you for helping me with this. The gui works well. Is there any other decals like this one. What I mean is, any other URL based decals, and not just user images? bluestreakejjp 41 — 6y
0
You can also get images of certain assets like catalog items. It is mentioned in this scriptinghelper post. https://scriptinghelpers.org/questions/30716/how-do-you-get-an-items-image-in-game User#18718 0 — 6y
Ad

Answer this question