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

A Script that equips a tool OnTouch only works in studio and shows no errors in the player?

I made this script to equip a tool on touch as i have backpack disabled and only want the tool to be equipped when entering a specific area.

function onTouched(hit)
	if game.ServerStorage.Main.Values.ToolEquip.Value == 0 then
hit.Parent.Humanoid:EquipTool(game.ServerStorage.Main.Parts.R15)
game.ServerStorage.Main.A1Enemies:Clone().Parent = game.Workspace.Npc
game.ServerStorage.Main.Values.ToolEquip.Value = 1
	end
end

connection = script.Parent.Touched:connect(onTouched)

The Value of "ToolEquip" is 0, and this gets no errors.

3 comments

0

you should clone the tool into the character instead of reparenting it from serverstorage

0

Remember ServerStorage is only server side, so the client cannot access it. Maybe move it to replicated storage. Because thats both client and server sided.

0

Thanks for the suggestion ill try it out.

2 answers

✓ Accepted answer

If you have backpack disabled, you can allow the player not to manually equip it. So you can still have the tools in starterpack, as you normally would.

To ensure you have backpack disabled the correct way, refer to this.

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false) --In a LocalScript within StarterPlayerScripts

Then you can prevent the player from equipping the tool, by enabling ManualActivationOnly.(A property of the tool class.) Once you do that, you can use this code to equip the tool.

Player.Character.Humanoid:EquipTool(Player.Backpack:FindFirstChild("toolname"))

Thank you "RubenKan" and "GottaHaveAFunTime", I took both your advice and it works, I cloned instead of moving it and cloning it into the Player instead of equipping it from ServerStorage fixed it.

This script works if anyone needs it for their game also to show you what i changed to fix it.

function onTouched(hit)
	if game.ServerStorage.Main.Values.ToolEquip.Value == 0 then
		game.ServerStorage.Main.Parts.R15:Clone().Parent = hit.Parent
		game.ServerStorage.Main.A1Enemies:Clone().Parent = game.Workspace.Npc
		game.ServerStorage.Main.Values.ToolEquip.Value = 1
		script.Parent.Parent.Tool2.ToolEquip.Disabled = true
		script.Disabled = true
	end
end

connection = script.Parent.Touched:connect(onTouched)

I appreciate all the help, the game if you're wondering is "/games/768440986/No-Name-Quest" Have a great day :).

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