I Tried To Use A Tool That Gives A Accessory To The Player, but it doesn't work? Please Help
Local Script Inside The Tool:
01 | local tool = script.Parent |
02 | local use = script.Parent.Sounds.Cape |
03 | local RS = game:GetService( "ReplicatedStorage" ) |
04 | local Wear = RS:FindFirstChild( "SigilWear" ) |
05 | local Unwear = RS:FindFirstChild( "SigilUnwear" ) |
06 | local wearing = false |
07 |
08 |
09 | tool.Deactivated:Connect( function () |
10 | if not wearing then |
11 | use:Play() |
12 | Wear:FireServer() |
13 | wearing = true |
14 | else |
15 | use:Play() |
16 | Unwear:FireServer() |
17 | wearing = false |
18 | end |
19 | end ) |
The script in server script service:
01 | local RS = game:GetService( "ReplicatedStorage" ) |
02 | local Wear = RS:FindFirstChild( "SigilWear" ) |
03 | local Unwear = RS:FindFirstChild( "SigilUnwear" ) |
04 | local helm = RS:FindFirstChild( "Sigil" ) |
05 | local plr = game.Players.LocalPlayer |
06 | local char = ((plr.Character and plr.Character.Parent) and plr.Character) or plr.CharacterAdded:Wait() |
07 | local human = char:WaitForChild( "Humanoid" ) |
08 |
09 | Wear.OnServerEvent:Connect( function () |
10 | sigilclone = helm:Clone() |
11 | human:AddAcessory(sigilclone) |
12 | end ) |
13 |
14 | Unwear.OnServerEvent:Connect( function () |
15 | sigilclone:Destroy() |
16 | end ) |
first things first you cannot use LocalPlayer in a server script as this is a client thing. the way you can do it is pass the character instance through the remote event. local script
01 | local tool = script.Parent |
02 | local use = script.Parent.Sounds.Cape |
03 | local RS = game:GetService( "ReplicatedStorage" ) |
04 | local Wear = RS:FindFirstChild( "SigilWear" ) |
05 | local Unwear = RS:FindFirstChild( "SigilUnwear" ) |
06 | local wearing = false |
07 | local char = game.Players.LocalPlayer.Character.Humanoid |
08 |
09 | tool.Deactivated:Connect( function () |
10 | if not wearing then |
11 | use:Play() |
12 | Wear:FireServer(char) |
13 | wearing = true |
14 | else |
15 | use:Play() |
16 | Unwear:FireServer(char) |
17 | wearing = false |
18 | end |
19 | end ) |
server script
01 | local RS = game:GetService( "ReplicatedStorage" ) |
02 | local Wear = RS:FindFirstChild( "SigilWear" ) |
03 | local Unwear = RS:FindFirstChild( "SigilUnwear" ) |
04 | local helm = RS:FindFirstChild( "Sigil" ) |
05 |
06 | Wear.OnServerEvent:Connect( function (player, human) |
07 | sigilclone = helm:Clone() |
08 | human:AddAcessory(sigilclone) |
09 | end ) |
10 |
11 | Unwear.OnServerEvent:Connect( function (player) |
12 | sigilclone:Destroy() |
13 | end ) |