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 4 days ago
Edited 4 days 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 2583 — 4d
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 55 — 4d
0
Thanks for the suggestion ill try it out. PastDays 2 — 3d

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

2 answers

Log in to vote
0
Answered by
Kulh 39
4 days ago
Edited 4 days 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 3 days ago
Edited 3 days 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