Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

7 comments

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?

0

Doesn't work but the item has a mesh, does that affect anything?

0

Oh yeah, it doesn't even print it when a player touches it...

0

Is the script a LocalScript or just a Script? Where is the script located?

0

You gotta check if it's a player or not; if a object that isn't a character/ player, it will not work.

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.

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.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.