I am trying to add an aura script to the player whenever the player spawns if their datastore value of hasShock is true. I've tried a ton of different things but nothing seems to be working.
local Players = game:GetService("Players") local shock tool = game.Lighting:findFirstChild("LightningAura") local function onCharacterAdded(character) if(shock == true) then print("this works") else print("still works") end end Players.PlayerAdded:Connect(function(Player) shock = Player.pscripts.hasShock.Value if(Player.pscripts.hasShock.Value == true) then local a = tool:clone() a.Parent = Player.Character else print("Player doesn't have shock") end end)
That's the first thing I tried but it always said the player doesn't have shock.
~~~~~~~~~~~~~~~~~
tool = game.Lighting:findFirstChild("LightningAura") -- Put the name of your tool here.
game.Players.PlayerAdded:Connect(function(player) local pscripts = Instance.new("Folder") pscripts.Name = "pscripts" pscripts.Parent = player
local hasShock = Instance.new("BoolValue") --Change below for name hasShock.Name = "hasShock" -- Default value hasShock.Value = false hasShock.Parent = pscripts --Again name and default local hasSSJ = Instance.new("BoolValue") hasSSJ.Name = "hasSSJ" hasSSJ.Value = false hasSSJ.Parent = pscripts player.CharacterAdded:Connect(function(Character) Character:WaitForChild('Humanoid').Died:Connect(function() print("dead") local a = tool:clone() if(hasShock.Value == true) then print("Got this far") local a = tool:clone() a.Parent = player.Character end end) end)
end) ~~~~~~~~~~~~~~~~~
This is the second thing I tried. It got to the got this far print statement every time but it didn't get put in the players inventory. Is there another way to do this? Or is there a way to fix one of the other ones.
Now, Im no Scripting Expert, but I think your problem is happening is because you are giving the tool to the player when they are dead. Perhaps try creating a value inside the player, then activating it whenever the Player dies, waiting until the player respawns, and checking if the player has the value set to true. If the value is set to true, clone the tool into the player's avatar, like this:
player.CharacterAdded:Connect(function(Character) local GiveTool = Instance.new("BoolValue") GiveTool.Name = "givetool" GiveTool.Value = false GiveTool.Parent = player Character:WaitForChild('Humanoid').Died:Connect(function() print("dead") if(hasShock.Value == true) then print("Got this far") player.givetool.Value = true end end) if player.givetool.Value == true then local a = tool:clone() a.Parent = player.Character end end)
Now, like I mentioned before, Im not Scripting Expert, so this may or may not work for you.
NOTE: This is for lines 14 - 25