Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can somebody help me fix this script?

Can somebody help me fix this script? So it does half of what it's supposed to do. The second part, was from someone else helping me out, but it may have some errors to it. I need some fixes, so here's what part 2 is supposed to do, and part 1 is supposed to do

Part 1 is supposed to insert the ID, of the texture into the texture link, so it will change the swords TextureID, to what you put in it. This script works, so It doesn't need any fixes.

repeat wait() until game.Players.LocalPlayer

local player = Game.Players.LocalPlayer

local swordMesh = script.Parent

local GuiBar = player.PlayerGui.ScreenGui.Frame.TextBox 

GuiBar.FocusLost:connect(function() 

pcall(function()

swordMesh.TextureId = "http://www.roblox.com/asset/?id="..tostring(tonumber(GuiBar.Text)-1)

end)
end)

However part 2 is the one that's bugging me. Part 2 is supposed to save the texture so when a player was to die, then they would keep it. So it'd resolve the issue with people having to put the ID into the GUI constantly. Part 2 doesn't work, can somebody fix this?

function saveData(player)

player:SaveInstance("SwordTextureId", swordMesh.TextureId)

end

 

function loadData(player)

swordMesh.TextureId = player:LoadInstance("SwordTextureId")

end

function onUpdate()

if game.Players.LocalPlayer.Character.Humanoid.Health <= 0 then
saveData(game.Players.LocalPlayer)

end

wait(0.5) 

onUpdate() 

end

3 answers

I believe this was the error:

function saveData(player)

player:SaveInstance("SwordTextureId", swordMesh.TextureId)

end



function loadData(player)

swordMesh.TextureId = player:LoadInstance("SwordTextureId")

end

function onUpdate()

if game.Players.LocalPlayer.Character.Humanoid.Health <= 0 then
loadData(game.Players.LocalPlayer) 
--It used to be saveData, but I changed it to loadData, maybe that will help

end

wait(0.5) 

onUpdate() 

end

1 comment

0

Didn't work.

No, you didn't understand, I pm you the entire code, As I wrote in the last part, the "getplayerhealth" method is not called.

3 comments

0

I don't understand still..

0

You called "onUpdate()" when there wasn't a function named like that, you called it inside a NOT called function.

0

Oh, I saw that you put 2 end at the end of the code, anyway the code I gave should work

You dont need to use GetPlayerHealth method, you can use this game.Players.LocalPlayer.Character.Humanoid.Health

2 comments

0

Still, I need help with this it wont work.

0

Then give us the last part!

This discussion is preserved as it was. New answers, comments, and votes are closed.