Ad
Log in to vote
0

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

Asked by 2 months ago
Edited 2 months ago

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.

0
you should clone the tool into the character instead of reparenting it from serverstorage RubenKan 2658 — 2mo
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. GottaHaveAFunTime 122 — 2mo
0
Thanks for the suggestion ill try it out. PastDays 4 — 2mo

2 answers

Log in to vote
0
Answered by
Kulh 84
2 months ago
Edited 2 months ago

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"))
Ad
Log in to vote
0
Answered by 2 months ago
Edited 2 months ago

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 :).

Answer this question



Ad