Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Why does a script in a tool not work after being transferred from ReplicatedStorage? [Solved]

Asked by 4 years ago
Edited 4 years ago
--When a player spawns, sets up stuff for them
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local function onCharacterAdded(player)

    local lobbyTeam = game.Teams.Lobby
    --Well use the player in Players cause Team is not a child of the player model
    local teamPlayer = Players:WaitForChild(player.Name)
    if teamPlayer.Team ~= lobbyTeam then
        local stick = ReplicatedStorage.HittingStick
        local stickClone = stick:Clone()
        stickClone.Parent = teamPlayer.Backpack
        stickClone.Handle.Anchored = false
        stickClone.Top.Anchored = false
    end
end

Players.LocalPlayer.CharacterAdded:Connect(onCharacterAdded)

This is just a checker local script for when people spawn, not actually that relevant. But maybe problem is in code.

Basically, in my undeveloped game, there are two team blocks and if you touch one it loads your character and then spawns you in the map. It gives you a fighting stick then. But when I send a stick clone into the player's inventory from ReplicatedStorage, the Animation Script inside it I use (local script) seems to work, but the script for other stuff like damage does not run from the start. Can somebody please help me as to where the problem lies. What storage or area.

3 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

A script located in ReplicatedStorage, ServerStorage, ReplicatedFirst, StarterPack, Teams and Lighting won't run. I recommend parenting the script to ServerScriptService and making it a server script instead of a local script which you can't use game.Players.LocalPlayer, If you don't know how to. You can use an on player added function, More about the on player added function here.

Hope I helped, Have a good day! :)

0
So, if a script, even if it isn't in one of those places in the above, but originated from there, it will not run? Phyrixia 51 — 4y
0
Anyway, after I will have a look, but since there seems to be a solution, I think it is ok. Thank you! Phyrixia 51 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I would put the script in SSS (ServerScriptService) You could put it in workspace but not reccomended as it can be easily stolen. I would also use server scripts not local because local scripts do not work in SSS.

Log in to vote
0
Answered by
ghxstlvty 133
4 years ago

Like many of the other people said, I would also put the script in ServerScriptService. Use a server script if you are doing so. It is also recommended that you don't put the script in workspace.

0
My issue is that there is a weapon in ReplicatedStorage, with a script inside, and after transferring it out of there, the weapon script does not run. I do not want to move the weapon script to ServerScriptService, since that would mean I would have to change the weapon script. Sorry for not being detailed enough on where the script was as in the parent was the tool. I just realised. Phyrixia 51 — 4y
0
Ok fixed it. Just moved tool to ServerStorage, used a playerAdded event in another script with no specific localScript, and boom I dunno was too lazy to try but oh well I did so now it is solved. I just would like to know why the issue occurred, but I guess I will use ServerStorage for tools from now on... Maybe. Phyrixia 51 — 4y

Answer this question