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

Making an interactable brick when touching and key pressed?

Asked by 4 years ago

I spent an hour trying to figure this out and its going to drive me insane here's the code I got

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local UserInputService = game:GetService("UserInputService")
local Part = script.Parent
function yes()
    print("ok")
        UserInputService.InputBegan:Connect(function(InputObject, Processed)
                if InputObject.KeyCode == Enum.KeyCode.E then
                    print("got key!")
                    game.Players.PlayerRemoving:Connect(function(player)
                        local success, errormessage = pcall(function()
                            myDataStore:SetAsync(player.UserId.."-points",player.leaderstats.Points.Value)
                        end)

                        if success then
                            print("Player Data saved!")
                        else
                            print("Player Data cant be saved")
                            warn(errormessage)
                        end
                    end)
                end
            end)
        end
script.Parent.Touched:Connect(yes)

Its getting the player touching the block but not the key press. Much help appreciated!

Answer this question