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

This hit function works in testing mode but not in a server?

Asked by 7 years ago

This is the script:

script.Parent.Touched:connect(function(hit)
    print("he")
    if hit:FindFirstChild("Mesh") then
        local plv = game.Workspace.Jobs.Coffee.PlayersInArea:FindFirstChild(hit.PlayerName.Value)
        plv.Value = plv.Value + 100
    end
end)

But when I touch this block in a server it doesn't even print "he".

(You can probably ignore the 'if' part, but I'm leaving it in because it might be important.)

0
I've tested it in a server, and it seems to work just fine. Perhaps you have it as a LocalScript instead of a Server side script? Mr_Octree 101 — 7y
0
Doesn't work but the item has a mesh, does that affect anything? Neodosa 7 — 7y
0
Oh yeah, it doesn't even print it when a player touches it... Neodosa 7 — 7y
0
Is the script a LocalScript or just a Script? Where is the script located? Mr_Octree 101 — 7y
View all comments (3 more)
0
You gotta check if it's a player or not; if a object that isn't a character/ player, it will not work. TheeDeathCaster 2368 — 7y
1
Just read the rest; did you check for errors at all? My guess is that the script's parent may not have loaded, but if this's only a snippet of the actual code, we'll need to know in order to help you. TheeDeathCaster 2368 — 7y
0
Look. The problem isn't that stuff under the print command. The problem is that it won't print "he" at all. Also apparently it works now. Neodosa 7 — 6y

1 answer

Log in to vote
0
Answered by
Kulh 125
6 years ago

In line 4, the location of the players username (hit.PlayerName.Value) The PlayerName cannot be accessed here, hit is what has hit the part.

To find the username you would have to do: PlayerName = hit.Name (Hit would be the players character model, the name of the model would be the players name.)

game.Players.PlayerName.Value = game.Players.PlayerName.Value + 100

This accesses the value that i am assuming is in the Players folder. Since PlayerName is the name of the Player, the code is basically telling itself (If i was the player that hit the part)

game.Players.Kulh.Value = game.Players.Kulh.Value + 100

Example:

script.Parent.Touched:connect(function(hit)
    print("he")
    if hit:FindFirstChild("Humanoid") then -- If a player hits it
      local plv=game.Workspace.Jobs.Coffee.PlayersInArea:FindFirstChild(hit.Name) -- Gets model name (Player's Name)
        game.Players.plv.Value = game.Players.plv.Value + 100 -- Goes to the Players folder and locates the player by it's name (plv is the Players name) and adds 100 to the Value
    end
end)
Ad

Answer this question