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

Where should I place a server script that functions on Join?

Asked by 7 years ago

Here's my script;

local Players = game:GetService("Players")


local function onPlayerAdded(player)
    local ability = player:WaitForChild("Status"):WaitForChild("Ability")
    if ability.Value == "None" then
        return
    end
    if ability.Value == "Magnet" then
        local Clone = game.ReplicatedStorage:WaitForChild("MagnetPunch"):Clone()
        Clone.Parent = player.Backpack
    end
end

for _,player in pairs(Players:GetPlayers()) do
     onPlayerAdded(player)
end

Players.PlayerAdded:connect(onPlayerAdded)

It won't function so I don't know. There were no errors so I'm guessing I placed it in the wrong place. Where should I place it and if there are any errors please tell me.

2 answers

Log in to vote
0
Answered by 7 years ago

Scripts will execute their containing code whenever they are inside Workspace or ServerScriptService.> - From the wiki.

However, the problem is not in the placement. The problem is probably that there is no Magnet as value of status... So its just returning false. But if it's not that try printing 2 separate things one at the start of the function and one after the wait line.

0
Status is a model inside players containing stats and more BlackOrange3343 2676 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

It would probably be put in ServerScriptService or Workspace. I would think that it would be able to be put anywhere, though, as long as its in the server and not in the player.

Answer this question