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

IntValue script working for a solo player but when two players are present it breaks ?

Asked by 2 years ago

In a solo server it works perfectly as intended, but with 2 players when one of them walks through the door it works until the other player walks through, which gives this error:

https://imgur.com/a/boXU6oE

(the puzzle is to walk through a door 5 times locally to wake up the owner of the store)

local detection = game.Workspace.detectionzone
local employee = game.Workspace.ToFind["Snailmart Employee"]
local playere = game.Players.LocalPlayer
local db = false
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local employee2 = game.Workspace.minimumwagesnail
local employee3 = game.Workspace.wakeupsnail

    local please = Instance.new("IntValue",playere)
    please.Name = "Beeps"
    print(please.Value)
    wait(.5)

detection.Touched:Connect(function(hitpart)
    local PlayerFromCharacter = game:GetService("Players"):GetPlayerFromCharacter(hitpart.Parent)
    if PlayerFromCharacter then
        if db == false then
            db = true
            PlayerFromCharacter.Beeps.Value += 1
            detection.Sound:Play()
            wait(1.78)
            print(PlayerFromCharacter.Beeps.Value)
            if PlayerFromCharacter.Beeps.Value >= 5 then
                employee2.ding:Play()
                employee2.Sleep.Zs.Enabled = false
                employee2.Sleep.wakeup:Emit(1)
                employee.Position = Vector3.new(555.547, 30.827, -344.168)
                employee2.Sleep.wakeup.Enabled = false
                    for _, part in pairs(employee2:GetChildren()) do
                        if part:IsA("Part") or part:IsA("UnionOperation") then
                        part.Transparency = 1
                            for _, part2 in pairs(employee3:GetChildren()) do
                                if part2:IsA("Part") or part2:IsA("UnionOperation") then
                                part2.Transparency = 0
                            end
                        end
                    end
                end
            end
            db = false
        end
        end
    end)    

(forgive my horrible looking code pls)

1 answer

Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
2 years ago

This is a local script. This means each player has its own copy of it. Therefore there is no need to run this function for any other player than local player.

Replace line 16 with this:

if PlayerFromCharacter == game.Players.LocalPlayer then

Hope this helps.

0
tysm. reddit gave me 10 paragraphs just to tell me how I was wrong and they weren't even right. thanks! kek_productions 7 — 2y
Ad

Answer this question