hello! i am trying to make a script so that when a player presses F, a certain accessory appears on their character. But i want to make it so that this happens only if the player has a different accessory, so like when they “trigger” the accessory by pressing f, a new accessory shows up on their character. I wrote my problem at the end
this is my local script inside of starterplayerscripts:
local uis = game:GetService("UserInputService")
local rp = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F and player.Character.Pully then
rp.Chainsaw:Clone().Parent = player.Character
end
end)
PROBLEM: when i click f, the accessory comes into the workspace but it just falls to the ground and doesnt spawn on the characters head, but where i left it last when it was in the workspace.
you probably need to attach the accessory to the character. either through weld or find some way for roblox to automatically kick in and make the character wear the item. i cant help you on this part though, i basically never work with accessories. i do think there was a plugin somewhere that made accessories automatically wearable when placed into a character.
You have 2 issues here.
The first one is that you are not using a function named AddAccessory from the character’s humanoid.
The second one is that you are executing this code from a local script and not a server script.
For organization, put a script in ServerScriptService and name it whatever you want, and then maybe just put a folder in ReplicatedStorage named “Remotes” and a remote event named “GiveAccessory” inside of said folder so that your already existing local script can communicate to the script you put in ServerScriptService.
If you follow the structure I suggested earlier, you can copy and paste the code below to add/replace code in the scripts.
Code for the script in ServerScriptService:
local rp = game:GetService("ReplicatedStorage")
local Remotes = rp:WaitForChild("Remotes")
local GiveAccessory = Remotes:WaitForChild("GiveAccessory ")
--
GiveAccessory.OnServerEvent:Connect(function(player)
local Character = player.Character
if Character and Character:FindFirstChild("Humanoid") and Character:FindFirstChild("Chainsaw") == nil then
local Humanoid = player.Character.Humanoid
Humanoid:AddAccessory(rp.Chainsaw:Clone())
end
end)
Replace input code for your existing local script:
local Remotes = rp:WaitForChild("Remotes")
local GiveAccessory = Remotes:WaitForChild("GiveAccessory")
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F and player.Character:FindFirstChild("Pully") then
GiveAccessory:FireServer()
end
end)
Something like this should work! BUT be sure to change ONE thing. Instead of putting the LocalScript in StarterPlayerScripts, put it inside of StarterCharacterScripts instead.
local uis = game:GetService("UserInputService")
local rp = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local IDK = rp.Chainsaw:Clone()
uis.InputBegan:Connect(function(input, gameprocess)
if gameprocess then return end
if input.KeyCode == Enum.KeyCode.F then
IDK.Parent = player.Character:WaitForChild("Head", math.huge) or player.Character.Head
local Weld = Instance.new("Weld")
Weld.Parent = IDK
Weld.Part0 = IDK
Weld.Part1 = player.Character:WaitForChild("Head", math.huge) or player.Character.Head
end
end)
Also you valid for watching chainsawman Be sure to ask if there’s any questions!
Also sorry but i forgot to state, this isn’t filtering enabled meaning other players wont be able to see it on their screen. I’m working on the filtering enabled version and ill put it here when I’m done
Alright, heres the filtering enabled version. I’ve tested this so it should be fully working.
if you’re too lazy its ok just download this Chainsaw.rbxm (4.3 KB)
here’s what to do tho
Put localscript inside of starterpack
What to put in the script:
local rp = game.ReplicatedStorage
local Chainsaw = rp.Chainsaw
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input,isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.G then
print("Chainsaw Transformation")
Chainsaw:FireServer()
end
end)
2.Put a script inside of serverscriptservice
what to put in the script:
local rp = game.ReplicatedStorage
local Chainsaw = rp.Chainsaw
local Accessories = script.Accessory
Chainsaw.OnServerEvent:Connect(function(player)
local char = player.Character
local humrp = char.HumanoidRootPart
local torso = char.Torso
local hum = char.Humanoid
local ChainsawHead = Accessories.Chainsaw:Clone()
ChainsawHead.Parent = char.Head
local Weld = Instance.new("Weld")
Weld.Parent = ChainsawHead
Weld.Part0 = ChainsawHead
Weld.Part1 = char.Head
end)
Put a folder inside of the serverscript and name it exactly: Accessory
Make sure to put your accessory inside and name it exactly: Chainsaw
Put a remotevent in replicatedstorage and name it exactly: Chainsaw
and yay you’re done
this is better because other players can see your transformation / the accessory attach to your head