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

How to make temporary variable not reset?

Asked by 11 months ago

Here is better explanation

I am making equip uniform (shirt + pants) system, where when you click on a button, you get uniform and when you die/reset (not fricking leave, so databases are not neccessary), uniform you wore stays, until you leave/change them (if change, temporary value changes)

Script:

local ReplicatedStorage = game.ReplicatedStorage
local RemoteEvent = ReplicatedStorage.GiveShirt
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAppearanceLoaded:Connect(function(character)
        local Temporary1 = character:FindFirstChild("shirtsaver")
        local Temporary2 = character:FindFirstChild("pantsaver")

        RemoteEvent.OnServerEvent:Connect(function(player, shirtTemplate, pantsTemplate)
            if shirtTemplate == "607785314" and pantsTemplate == "129458426" then
                character.Shirt.ShirtTemplate = game:GetService("InsertService"):LoadAsset(shirtTemplate).Shirt.ShirtTemplate
                character.Pants.PantsTemplate = game:GetService("InsertService"):LoadAsset(pantsTemplate).Pants.PantsTemplate
                Temporary1.Value = 607785314
                Temporary2.Value = 129458426
            end
        end)

        character.Shirt.ShirtTemplate = game:GetService("InsertService"):LoadAsset(Temporary1.Value).Shirt.ShirtTemplate
        character.Pants.PantsTemplate = game:GetService("InsertService"):LoadAsset(Temporary2.Value).Pants.PantsTemplate
    end)
end)
0
When I'm doing storage of things that I want to keep consistent throughout the game experience, I often have a value in server storage (or replicated storage if I need it) that I just modify.. joshthegamer456 93 — 11mo

1 answer

Log in to vote
0
Answered by 11 months ago
Edited 11 months ago

Here's a simple way to do this. You will need a server script, local script, a RemoteEvent in ReplicatedStorage, and a Folder in ReplicatedStorage, name it "Clothing". Inside the Clothing folder insert a shirt and pants, put your shirt/pants ids in them.

https://gyazo.com/ecaa4f4b2d49fd80dcdf39c97f66115b

Your ReplicatedStorage should look like that.

Server script in ServerScriptService

local shirtid = game.ReplicatedStorage:WaitForChild("Clothing").Shirt.ShirtTemplate
local pantsid = game.ReplicatedStorage:WaitForChild("Clothing").Pants.PantsTemplate

game.ReplicatedStorage:WaitForChild("RemoteEvent").OnServerEvent:Connect(function(plr)
    plr.Character.Shirt.ShirtTemplate = shirtid
    plr.Character.Pants.PantsTemplate = pantsid
    plr.CharacterAdded:Connect(function(chr)
        repeat task.wait() until chr
        chr.Shirt.ShirtTemplate = shirtid
        chr.Pants.PantsTemplate = pantsid
    end)
end)

Local script in your button:


script.Parent.MouseButton1Click:Connect(function(plr) game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireServer() end)
Ad

Answer this question