ooops my bad, i forgot you didnt mentioned plr.character
script.Parent.Parent.ProximityPrompt.Triggered:Connect(function(plr)
local shirt = script:FindFirstChildOfClass("Shirt")
local pants = script:FindFirstChildOfClass("Pants")
plr.leaderstats.Money.Value += -50
if shirt and pants then
local character = plr.Character
local plr_shirt = character:FindFirstChildOfClass("Shirt")
local plr_pants = character:FindFirstChildOfClass("Pants")
if plr_pants and plr_shirt then
plr_shirt.ShirtTemplate = shirt.ShirtTemplate
plr_pants.PantsTemplate = pants.PantsTemplate
end
end
end)
You donāt make sure that leaderstats or money is a thing.
You donāt make sure that they have enough money
You donāt make sure that character is a thing (or humanoid)
You donāt make sure that theyāre alive
You donāt make sure that their character is close to the object (10-20 studs, so they canāt buy it from 1000 studs away) - This one is picky, so I didnāt include it in my own script. It matters more in simulators or shooting games.
You donāt do so Shirt or Pants spawn onto their character if it isnāt there, even though they paid for it to happen
This means the shirt and pants doesnt exists some where.
Put your shirt and pants under the script
script.Parent.Parent.ProximityPrompt.Triggered:Connect(function(plr)
local shirt = script:FindFirstChildOfClass("Shirt")
local pants = script:FindFirstChildOfClass("Pants")
if plr.leaderstats.Money.Value >= 50 then
if plr.Character.Humanoid.Health <= 0 then
return warn("Cant buy shirt they are already dead")
end
plr.leaderstats.Money.Value -= 50
else
return warn("Player dont have enough cash.")
end
if shirt and pants then
local character = plr.Character
local plr_shirt = character:FindFirstChildOfClass("Shirt")
local plr_pants = character:FindFirstChildOfClass("Pants")
if not plr_pants then
plr_pants = Instance.new("Pants")
plr_pants.PantsTemplate = pants.PantsTemplate
end
if not plr_shirt then
plr_shirt = Instance.new("Shirt")
plr_shirt.ShirtTemplate = shirt.ShirtTemplate
end
if plr_pants and plr_shirt then
plr_shirt.ShirtTemplate = shirt.ShirtTemplate
plr_pants.PantsTemplate = pants.PantsTemplate
end
else
warn("Shirt and pants cant be found under the script")
end
end)
@TortenSkjold there iāve covered few issues youāve said
And about the last second point, hes using proximity prompt so no need to find player distance from the dummy.
script.Parent.Parent.ProximityPrompt.Triggered:Connect(function(plr)
local shirt = script:FindFirstChildOfClass("Shirt")
local pants = script:FindFirstChildOfClass("Pants")
if plr.leaderstats.Money.Value >= 50 then
if plr.Character.Humanoid.Health <= 0 then
return warn("Cant buy shirt they are already dead")
end
plr.leaderstats.Money.Value -= 50
else
return warn("Player dont have enough cash.")
end
if not shirt then
return warn("Shirt cant be found under the script")
end
if not pants then
return warn("Pants cant be found under the script")
end
if shirt and pants then
local character = plr.Character
local plr_shirt = character:FindFirstChildOfClass("Shirt")
local plr_pants = character:FindFirstChildOfClass("Pants")
if not plr_pants then
plr_pants = Instance.new("Pants")
plr_pants.PantsTemplate = pants.PantsTemplate
end
if not plr_shirt then
plr_shirt = Instance.new("Shirt")
plr_shirt.ShirtTemplate = shirt.ShirtTemplate
end
if plr_pants and plr_shirt then
plr_shirt.ShirtTemplate = shirt.ShirtTemplate
plr_pants.PantsTemplate = pants.PantsTemplate
end
else
warn("Shirt and pants cant be found under the script")
end
end)
The reason this was not working was because some roblox shirt IDās can be changed ingame. Plus you cannot get a shirt template by just simply using itās ID. You have to reference Itās whole URL To be able to do so. Hereās an example on how to do so
Do the same thing on a pant clothing with a pants template. Also hereās the code I was using modified so you can use it on your game
-- Variables
local Debris = game:GetService("Debris")
local Price = 50
local shirt = Instance.new("Shirt")
local pants = Instance.new("Pants")
pants.PantsTemplate = "http://www.roblox.com/asset/?id=144076759" -- Change To what I've shown in the tutorial for the pants
shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=398635080" -- Change To what I've shown in the tutorial for the shirt
script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
if plr.leaderstats.Money.Value >= 50 then
plr.leaderstats.Money.Value -= 50
if plr.Character:FindFirstChildOfClass("Humanoid") and plr.Character:FindFirstChildOfClass("Humanoid").Health >= 1 then
Debris:AddItem(plr.Character:FindFirstChildOfClass("Shirt"), 1)
Debris:AddItem(plr.Character:FindFirstChildOfClass("Pants"), 1)
shirt.Parent = plr.Character
pants.Parent = plr.Character
end
end
end)
If this does give an error about the leader stats It just simply means I did not select the leaderstats location right.
1
you are adding an integer when you can subtract a pos. number
2
the script will always subtract the amount of cash, even if itās insufficient
3
you are trying to get the shirts from the Player, not the Character
4
why are you trying to get āidsā from an instance instead of a string/number
local shirt = script:FindFirstChild("Shirt")
local pants = script:FindFirstChild("Pants")
local cost = 50 --expense
script.Parent.Parent.ProximityPrompt.Triggered:Connect(function(plr)
local leaderstats = plr.leaderstats --get leaderstats
if leaderstats then -- if true then
if leaderstats.Money.Value >= cost then -- if player has enough money to buy
leaderstats.Money.Value -= cost -- subtract
plr.Character.Shirt.ShirtTemplate = shirt.ShirtTemplate --get id + get player + paste to player's shirts
plr.Character.Pants.PantsTemplate = pants.PantsTemplate
else -- if agurement is not met
print("not enough dollars") -- print to output
end
end
end)
hereās some stuff you can get to know if then end -- if loop | if requirement is met then it will do a certain function
example
local val = true
if val == true then
print("true")
end
if then else(if) end --if requirement is met then it will do a function, but if it doesn't meet it will do another function under the [else] subloop
example
local val = true
if val == true then
print("true")
val = false -- turn value to false
else
print("false")
end