Hey! So I have been working on a game for the past few days and am having a huge problem with a backpack system I created.
I have it so when I click an ImageButton it makes the shirt invisible. However it is only going transparent locally. For everyone else the shirt is still showing.
I have tried to look all over the Developer Forum but I’m having no luck.
What I need:
-By clicking a GUI button the shirt will go transparent.
-The shirt is a union so keep that in mind.
I just need a button to make an object inside of your own player invisible.
4 Likes
There is a Server-Client Relationship. I recommend learning and understanding that its a really important concept that is key to development
You need to utilize RemoteEvents to achieve actions such as a client request.
2 Likes
I forgot to mention, but I have tried using RemoteEvents to try and do this. However I am not very good at working with those just yet. Is there anyway you can elaborate, or give a few lines of code?
2 Likes
We can get started if you show me a code example of how you change the shirt’s transparency.
Then I’ll ask you do to the following things
- Make the
RemoteEvent
- Make a Script in
ServerScriptService
for Remote Handling
- Paste Example Code(That ill setup) inside Remote Handler
- Make a Variable Calling Remote (Inside
localscript
) So you can :FireServer()
- Test n Debug
I’ll get started on the Example code. As soon as you show how a line of you setting transparency locally, I’ll use that as a reference.
Edit: Ready when ever you are…
2 Likes
from the local script you can use
:FireServer() function of remote event
from the server script you can use
.OnServerEvent(playerObj)
playerObj is passed automatically
you can use the player object
find character using workspace[playerObj.Name]
find the shirt inside the character
make it transparent from the serverscript
Here is what I used for the code:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
script.Parent.Torso.MouseButton1Click:Connect(function()
ClonedChar.TorsoShirt.Transparency = 1
char.TorsoShirt.Transparency = 1
script.Parent.Parent.Inv.TitleImageLabel.TextLabel.Text = “Torso”
end)
The “script.Parent.Torso” is the ImageButton, and the TorsoShirt is the union that I need to change the transparency of.
- NOTE: Ignore everything in bold as it does not have anything to do with the actual character itself. It is for a ViewportFrame that is already working.
1 Like
If you made the RemoteEvent
and Remote Handler Script
then I we just paste this into the script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvent --// Rename if you wish
RemoteEvent.OnServerEvent:Connect(function(Player,Bool)
print(Player.Name .. " Fired Remote ")
local Player_Shirt = Player.Character.TorsoShirt --// Player Shirt Var
local Transparency
if Bool then Transparency = 1 else Transparency = 0
if Player_Shirt then --// Conditional
print("Shirt found Setting to "..tostring(Bool))
Player_Shirt.Transparency = Transparency
end
end)
Edit: After we know it works, we can remove the prints.
DISCLAIMER Code below is for local script
you also need to Fire the RemoteEvent
from the local script first declare the variable for RemoteEvent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvent
then Inside MouseButton1Down
you will :FireServer()
RemoteEvent:FireServer(true)
1 Like
Ok, so I have a RemoteEvent inside of ReplicatedStorage and a script inside of ServerScriptService. I created a new LocalScript inside of the ImageButton and put the code you said in. Is this the proper way to format it, and if so its not working.
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local RemoteEvent = ReplicatedStorage.RemoteEvent
script.Parent.MouseButton1Down:Connect(function()
RemoteEvent:FireServer(true)
end)
You could have just pasted the lines inside your current local script.
Like the Remote Vars outside the event and the :FireServer()
inside the event but whatever you wish
Edit: like this
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local Remote = ReplicatedStorage.RemoteEvent
script.Parent.Torso.MouseButton1Click:Connect(function()
Remote:FireServer(true)
--ClonedChar.TorsoShirt.Transparency = 1 --// Wasnt Defined
char.TorsoShirt.Transparency = 1
script.Parent.Parent.Inv.TitleImageLabel.TextLabel.Text = “Torso”
end)
Earlier you said that there should be a variable. What type should it be? I see that you used Bool in one of the scripts you sent should it be that type? I have the variable inside of the LocalScript.
I tried to include as many comments as I could explaining it, but I missed key details, and I apologize for that.
When you make your RemoteEvent
you can decide what variables need/want
In this case I just used Bool
keep in mind it could be named anything you want and I believe you can send multiple values via the Parameters
Edit: In this scenario, I used “Bool” only to send to the server if you want true or false for the Character shirt. BUT keep in mind it could of been named “ShirtVisible” and be a bool value or a number value I hope it makes a little sense
1 Like
Hey there,
add server script inside the buttton and include this code
script.Parent.MouseButton1Click:Connect(function()
local plr=script.Parent.Parent.Parent.Parent
local character= game.Workspace[plr.Name]
character.TorsoShirt.Transparency = 1
end)
change or add any necessary code
1 Like
Alright so the code is working however it is still only working locally. I am testing in game with one of my alt accounts and it is doing the same thing as before.
1 Like
What does the output log say?
I didn’t expect it to work right off the bat. Can you check your output log for what is said? So we can start debugging.
I suspect that the RemoteEvent wasn’t declared properly. That could be just the start, though
1 Like
Ignore the error already in there as that is something else entirely.
The remote seems to be firing, however it’s not causing the shirt to go transparent for everyone.
EDIT: It is making it invisible for the local player.
That isn’t actually possible if the server is firing the remote and fully rendering the script and conditional it would no doubts. there should be two prints though you are using my code exactly? cause if so there SHOULD be a second print
print("Shirt found Setting to "..tostring(Bool))
this should print
Edit: Let’s start by exploring the Explorer
tab and index the shirt properly
local Player_Shirt = Player.Character.TorsoShirt --// Player Shirt Var
lets fix this line
1 Like
Check my last message. I just added a lil info can you open explorer in a playtest and send a screenshot and show where the shirt is within the player
maybe you don’t need to if you could handle indexing and updating this line
local Player_Shirt = Player.Character.TorsoShirt --// Player Shirt Var
EDIT : actually its my fault messed up the scope of the first conditional
1 Like
So I have a StarterCharacter. I’m not sure if that could be messing things up but heres the format of the Character.
1 Like
Sorry about that I made a conditional to declare Transparency variable and forgot to add end
Updated the script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvent --// Rename if you wish
RemoteEvent.OnServerEvent:Connect(function(Player,Bool)
print(Player.Name .. " Fired Remote")
local Player_Shirt = Player.Character.TorsoShirt --// Player Shirt Var
local Transparency
if Bool then Transparency = 1 else Transparency = 0 end --// I forgot end here
if Player_Shirt then --// Conditional
print("Shirt found Setting to "..tostring(Bool))
Player_Shirt.Transparency = Transparency
end
end)
3 Likes