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

Winpad wont work with local scripts but works with server scripts? (ANSWER IT)

Asked by 4 years ago

Alright, im asking the same question the third time yet i dont recieve an answer, please do it.

After people complained the winpad teleporting everyone to the lobby when someone touches it, I changed it to local script. However it dosent do anything but in the output, no errors. I would appreciate anyone whoever answers.

local debounce = false
local part = script.Parent
local LobbySpawn = game.Workspace.Lobby.Floor.Center.SpawnLocation

part.Touched:Connect(function()
   if debounce == false then
   debounce = true

   for _, player in pairs(game.Players:GetPlayers())do
        local char = player.Character
        char.HumanoidRootPart.CFrame = LobbySpawn.CFrame

   wait(1)

   for i,v in pairs(game.Players:GetPlayers()) do
        if v:FindFirstChild("leaderstats") then
        v.leaderstats.Credits.Value = v.leaderstats.Credits.Value + 20
        v.leaderstats.Wins.Value = v.leaderstats.Wins.Value + 1

   debounce = false
  end
end
end
end
end)
0
A local script won't make it better but worse because of filtering enabled. I think you should change it back to a server script. IceyTazeForLife 253 — 4y
0
ok but i dont want the win pad to teleport everybody to the lobby when someone touches it DecalMaker2468 21 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

By itterating through all the players you applied changes that will affect everyone in the game. If you did not know, part.Touched supplies the function with the part that touched it.

Knowing this might be a body part we can try to find the player from the character using game.Players:GetPlayerFromCharacter. A body part is a child of the char, so the char is the parent of the body part.

With the player you can now access the character to change the HumanoidRootPart position.

Example:

part.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then    -- Check if the player is found from the character
        local char = player.Character
        local HumanRp = char.HumanoidRootPart
        HumanRp.CFrame = game.Workspace.Spawn1.CFrame
        -- You can also add debounce to this script
    end
end)

I hope this helps :)

0
it works! DecalMaker2468 21 — 4y
Ad
Log in to vote
1
Answered by
NordicM 77
4 years ago

When you use part.Touched, you get a parameter in the function which will be the part that touched it... In this example you can see what touched the part. (You can change the bodyPart to what ever you like...)

part.Touched:Connect(function(bodyPart)
    print(bodyPart.Name)
end)

If you get the parent of the bodyPart you will get the character. You have to check if a body part hit the winpad, so check if it has a humanoid

part.Touched:Connect(function(bodyPart)
    local character = bodyPart.Parent
    if character:WaitForChild("Humanoid") then
        print("Success!")
    end
end)

If you need the player to add leaderstat points you can use this!

part.Touched:Connect(function(bodyPart)
    local character = bodyPart.Parent
    if character:WaitForChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(character)
    end
end)

Hope it helped!

Answer this question