I’m trying to make an overhead tag which displays if you are on console, mobile, or computer. I have the overhead gui sorted out and working, but what I am having an issue with is assigning an image ID to the imagelabel.
Without my script, it works fine with displaying the placeholder, so I think it could be an issue with what I am assigning before the image ID (rbxassetid://)
Here is my script:
local ismobile = game:GetService('UserInputService').TouchEnabled
local isconsole = game:GetService('UserInputService').GamepadEnabled
local isdesktop = game:GetService('UserInputService').KeyboardEnabled
local dev = script.Parent
if ismobile == true then
dev.Image = "rbxassetid://"..12240871627
elseif isconsole == true then
dev.Image = "rbxassetid://"..12240876390
elseif isdesktop == true then
dev.Image = "rbxassetid://"..12240888456
else
end
Your code may not be working because you are using a LocalScript inside of an object in the workspace that is not a Tool or a character model.
Doing the following may help: create a RemoteEvent and a Script, and put your LocalScript inside of StarterPlayerScripts or StarterCharacterScripts; fire the RemoteEvent from the client, telling the server which platform the client is playing on; then, from the server’s side, set the BillboardGui's image using the provided information from the client.
Example: In ReplicatedStorage
LocalScript in StarterPlayerScripts/StarterCharacterScripts
-- // VARIABLES
-- / Services
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- / Remote
local remote = -- (The remote's location.)
-- / Other
local platform = ""
-- // MAIN
if UserInputService.TouchEnabled then
platform = "Mobile"
elseif UserInputService.GamepadEnabled then
platform = "Console"
elseif UserInputService.KeyboardEnabled then
platform = "Computer"
end
remote:FireServer(platform)
Script in ServerScriptService
-- // VARIABLES
-- / Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- / Remote
local remote = -- (The remote's location.)
-- / Arrays
local imageIds = {
Mobile = 12240871627,
Console = 12240876390,
Computer = 12240888456
}
-- // MAIN
remote.OnServerEvent:Connect(function(player, platform)
-- Get the image.
local imageId = imageIds[platform]
if not imageId then
return
end
-- Edit the overhead GUI.
-- Remove 'player.CharacterAdded:Wait()' if LocalScript is in StarterCharacterScripts.
local character = player.Character or player.CharacterAdded:Wait()
local overheadGui = -- (The BillboardGui's location.)
overHeadGui.lmageLabel.Image = "rbxassetid://"..tostring(imageId)
end)
If you put the LocalScript inside of StarterCharacterScripts, the remote will fire from the client every time the character (re)spawns.
I don’t think my current problem is anything wrong with your script, it is likely how I set everything up.
The script doesn’t prevent the GUI placeholder from showing, but it still doesn’t change the image id.
Here is the script:
-- // VARIABLES
-- / Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- / Remote
local remote = ReplicatedStorage.RemoteEvent
-- / Arrays
local imageIds = {
Mobile = 12240871627,
Console = 12240876390,
Computer = 12240888422
}
-- // MAIN
remote.OnServerEvent:Connect(function(player, platform)
local character = player.Character or player.CharacterAdded:Wait()
local imageId = imageIds[platform]
if not imageId then
return
end
ReplicatedStorage.NameGUI.dev.Image = "rbxassetid://"..imageId --The line of code I wrote
end)
First I will make some changes to your variables.
Now let’s get UIS.
local UserInputService = game:GetService("UserInputService")
Now let’s make some variables.
local touch, gamepad, keyboard, mouse = UserInputService.TouchEnabled, UserInputService.GamepadEnabled, UserInputService.KeyboardEnabled, UserInputService.MouseEnabled
Now with this we can make a script:
if gamepad and not touch and not keyboard then
-- xbox
elseif touch and not gamepad and not keyboard and not mouse then
-- mobile
else
-- pc
end
Now you can use this, but this will only handle it client-sidedly. Now we should send a RemoteEvent and send through a parameter for mobile, xbox or pc. With this information and with the information that the server got (which includes the player parameter) we can edit the BillboardGui.
I am not quite sure where everything is located so I cant help with this.
I see that the image ID for Mobile results in a blank image. Have you tested out your images in the Studio before using them? The other two are IDs are not blank.
Edit: Wait, the mobile image works when I set it outside of the script. I do not know what the issue is. Maybe it is a bug.
Instead of concatenating (adding) the rbxassetid link to the id, just put the ID into the string. This probably raises an error for you because you are trying to add a string and an integer together. It would look like this:
local ismobile = game:GetService('UserInputService').TouchEnabled
local isconsole = game:GetService('UserInputService').GamepadEnabled
local isdesktop = game:GetService('UserInputService').KeyboardEnabled
local dev = script.Parent
if ismobile == true then
dev.Image = "rbxassetid://12240871627"
elseif isconsole == true then
dev.Image = "rbxassetid://12240876390"
elseif isdesktop == true then
dev.Image = "rbxassetid://12240888456"
else
end
It’s interesting that you’re trying to change the image ID on the client. Which means you would have to access the actual image, or load the ID into the game if it already isn’t. I’m not an expert at images, but that may not be possible to do on the client. You may want to look into that.
Import it into your workspace, then copy the Texture ID and paste it into your script.
Then go to test then click devices and choose a phone, and it should work.
I’m not sure if this made a difference, but following advice from @Jiraiyeh and @JustCrock, I removed my concatenation and I adeed my images into the asset manager.
Then, I inserted my script in to the imagelabel, and added the entire GUI into starterGUI.